Author | Topic: SocketRecv | |
---|---|---|
Raffaele Tammeo | SocketRecv on Wed, 08 Aug 2007 18:23:04 +0200 Hi all I work with ASINET since few days. My problem is the following: I don't succeed in receiving data in a server from a client, using socket. I try to use a socketlisten. Here is the code running on the server: nSocketListen := SocketCreate( ,nPort) //create the socket ... ... //now a client connects to me:i try to read data sent //now i execute the code on the server: SocketListen(nSocketListen) //i start listening nBytes := SocketRecv(nSocketListen, cRead) //i read the bytes from the queue msgbox("Received data:" + cRead) In the server I never read any data from client. I don't get any error at runtime. I get always nBytes=0. How can i do to get a well working listening? Is there something missing? Raffaele P.S. I must tell a thing for a full explain: When i make a send of data (in the client), all the following code works well: nSocketSend := SocketNew(, , , @nError) //create the new socket SocketConnect(nSocketSend, , cUrl, nPort) //create the connection to the server nWritten := SocketSend(nSocketSend, "Hallo everybody") //i write the data well read by the server | |
Phil Ide | Re: SocketRecv on Mon, 13 Aug 2007 16:03:07 +0100 Raffaele, When you set a socket to 'Listen', it merely listens for connections on that socket. What you must do when a client connects, is create a new socket which is bound to the incoming client connection and then read from the new socket. set to listen mode SocketListen( nListenSocket ) while !lExit allow break out of loop on exit condition nSocket := SocketAccept( nListenSocket ) if !(nSocket == NIL) process incoming data on nSocket endif enddo Regards, Phil Ide --------------------- www.xbhcl.com www.pbih.eu www.idep.org.uk/xbase --------------------- Read the docs. Wow, what a radical concept! |