Search Forums by tag:
Serial, mbed, compiler, ethernet, USB, I2C, SPI, interrupt, LCD, library, bug, HTTPServer, CAN, AnalogIn, adc, Power, Ticker, memory, pwm, SD Card, InterruptIn, rpc, Error, SDFileSystem, PwmOut, LocalFileSystem, UART, canbus, driver, TCP, interrupts, rtos, led, libraries, editor, timer, accelerometer, GPS, file, clock, website, C++, SD, frequency, reset, http, LPC11U24, flash, SDCard, RTC, DigitalIn, TCPSocket, problem, printf, Java, Servo, buffer, UDP, SerialPC, DMA, HTTPClient, Sleep, audio, pinball, MODSERIAL, NetServices, socket, array, compile, filesystem, RFID, beta, m3pi, write, LPC1768, multiple, newbie, keyboard, sensor, GPRS, Forum, digitalOut, assembly, debug, hardware, Speed, xbee, AnalogOut, RPCFunction, EthernetNetIf, Download, code, voltage, wait, network, C, suggestion, JTAG, keil, MATLAB, offline, Board, lwip, I2S, dead, Nokia6610, time, bluetooth, WiFly, current, tcp/ip, MODDMA, SPI Slave, pololu, robot, Communication, read, dac, string, pc, binary, filter, copy, USB Host, publish, rs232, DHCP, Host, Data Logging, windows, firmware, malloc, mp3, PCB, gcc, attach, program, fatfilesystem, class, email, arduino, stepper motor, WavePlayer, wifi, Nokia, camera, size, VGA, import, documentation, ide, linux, baud, TextLCD, Cortex-M0, M0, pointers, pullup, Relay, timing, function, latency, serial port, MIDI, compiler error codes, magjack, touch, screen, Production, client, server, stream, HID, breakout, FIFO, prototype, flashing, GPIO, sampling, Analog, display, api, ADXL345, Encoder, DSP, help, motor, sram, suggestions, PING, Terminal, link, browser, Pin, control, Eagle, Modbus, EEPROM, mac, Timeout, fopen, port, updates, usbserial, batteries, DMX, files, USBMIDI, scanf, protocol, PPP, slave, FTP, integer, noise, MODGPS, modem, float, threads, motors, for, monitor, Digital I/O, 7, Windows Serial Driver, pins, keypad, FAT, classes, webserver, delay, variables, time-triggered, c programming, labview, watchdog, post, math, Battery, LPCXpresso, MBED website, GSM, storage, nxp, mobileLCD, license, int, counter, baseboard, Assembler, Vin, rj45, registers, E289, news, i2cmaster, amoled, Compiling, connect, revision, prototype to hardware, UMTSStick, Optocoupler, Robotics, search, oscillator, glitch, Websockets, load, find, real-time, routine, format, offline compile, powersource, driverlibrary, processing, networking, ID, umts, debugging, color, BUTTON, software, PS3, Images, wave, bin, const, SNMP, OSX, supply, peripheral, sensors, data, Design, PID, version, RIT, character, freeze, USBDevice, bus, ARM, wav, SRF08, heap, output, basic, TFT, QVGA, mysql, piezo, update, ID12, Pachube, player, DigitalInOut, object, cmsis, capture, IR, slow, 1768, PSP, OS, syntax, mbed.lib, EmbeddedArtists, NMEA, paste, project, Web, GUI, UART0, firefox, SQL, wakeup, RAM, bitmap, handler, security, 3D, bugs, OLED, Temperature, not, I/O, Bidirectional, rss, wireless, delete, resolved, LED1, LIS302, getc, Safari, Wi-Fi, wiki, PinNames, accounts, PS2, BusOut, projects, RS485, pythonHi Donatien,
>If you are ready to help, I would love having some feedback regarding bugs, but also ease of use and customization. So if you are ready to implement that stack in your project, I think it would be a great test!
Yes, I am ready. From what you say the architecture in your implementation fits perfectly the application I have. It seems like I will need the source code for getting started with sockets. Besides, to me source code is almost always better than documentation, so I can start before any documentation is available.
--
Ilya
Time flies! I was able to compile from source and run just the HTTP server part, did not try the sockets yet. Here are some random observations:
I've been playing with the socket API a bit as it seems to be just what I need, but I've run into a brick wall. Can anyone point me in the right direction? So far, I have:
#include "mbed.h"
#include "EthernetNetIf.h"
#include "TcpSocket.h"
#include "UdpSocket.h"
EthernetNetIf eth;
TcpSocket tcpSock;
UdpSocket udpSock;
int main() {
printf("Start\n");
printf("\r\nSetting up...\r\n");
EthernetErr ethErr = eth.setup();
if(ethErr) {
printf("Error %d in setup.\n", ethErr);
return -1;
}
IpAddr ip = eth.getIp();
printf("IP Address: %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]); // Turns out the library does this anyway
TcpSocketErr sockErr = tcpSock.bind(Host(IP_ADDR_ANY, 7)); // Trying to make a simple echo server on port 7
if(sockErr) {
printf("Error %d in binding TCP socket\r\n", sockErr);
return -1;
}
sockErr = tcpSock.listen();
if(sockErr) {
printf("Error %d in listening to TCP socket\r\n", sockErr);
return -1;
}
printf("Entering while loop just Net::poll()ing\r\n");
while(1) {
Net::poll();
}
} But now what, what do I do with the socket? I hooked up a method to be called on events using:
void onNetTcpSocketEvent(TcpSocketEvent e) {
switch (e) {
case TCPSOCKET_CONNECTED:
printf("TCPSOCKET_CONNECTED\r\n");
break;
case TCPSOCKET_ACCEPT:
printf("TCPSOCKET_ACCEPT\r\n");
break;
default:
printf("Socket event %d\r\n", e);
}
}
int main() {
// ...
void (*pt2Function)(TcpSocketEvent) = NULL;
pt2Function = &onNetTcpSocketEvent;
tcpSock.setOnEvent(pt2Function);
(*pt2Function) (TCPSOCKET_CONNECTED);
// ....
}
This calls the onNetTcpSocketEvent function on TCPSOCKET_ACCEPT, but I'm at a loss as to what I do next. I'm guessing something like:
Host *h;
TcpSocket **s;
TcpSocketErr tcpSockErr = tcpSock.accept(h, s);
if(tcpSockErr) {
printf("Error %d in accepting socket\r\n", tcpSockErr);
break;
}
IpAddr clientIp = h->getIp();
printf("Client: %d.%d.%d.%d", clientIp[0], clientIp[1], clientIp[2], clientIp[3]);
But this seems to die a horrible death when I try to call h->getIp(); If I can get this sorted, what I'd like to do is get this working as a basic echo server on TCP and UDP and then document it as some sort of guide to using this excellent socket API. In the meantime I've got my head buried in a C++ book as coming from the sheltered life of Java and C#, pointers are quite scary and as is quite possibly obvious from my last code snippet, I need to do a fair bit of learning.
Hi everyone,
First of all thank you for this feedback, I will take the time to look at these issues. Regarding the sockets API, I know that this seriously lacks documentation; I have to update the cookbook next week anyway, so the sockets API will probably be part of the new pages.
Meanwhile, I have released the source for the stack here, which can be useful if you want to get started furing the weekend: http://mbed.org/users/donatien/programs/NetServicesSource
Feel also free to have a look at this dedicated forum thread and this new wiki page.
Please log in to post a reply.
No tags
|
Hi Ilya,
I chose to build up that stack using different layers isolated from each other: the interface-specific layer (which basically contains the Ethernet driver and LwIP), the sockets API, and top-level services (HTTP server/client, NTP client, etc).
The whole stack is polling/events based, and apart from some thread-safe LwIP services, nothing is executed on interrupt. That way, functions in the stack can be non-blocking, and you can run multiple services at the same time (in your case an HTTP Server + a streaming server should not be a problem), plus you avoid loads of "threading" problems.
If you are ready to help, I would love having some feedback regarding bugs, but also ease of use and customization. So if you are ready to implement that stack in your project, I think it would be a great test!
I have not written some example programs for the sockets API yet, however the HTTP server/client and NTP client use that API, so if you want to have a look at the source code I can send it to you.
In the following days I will be writing more documentation, including some on the sockets API.
Donatien