[En-Nut-Discussion] More clients on the same TCP port

Ralph Mason ralph.mason at telogis.com
Fri Sep 29 11:25:58 CEST 2006


All psudo code... but

Void myserver{

Socket s= NutTcpCreateSocket(some_port)

While(!pigs_fly)
	NutThreadStart( socket_processor,  NutTcpAccept(my_socket));


}

Void socket_processor(socket s){
	While(there_is_stuff_to_do){
		NutTcpSend(), NutTcpReceive()
	}

      NutTcpCloseSocket()
	NutThreadExit()
}


-----Original Message-----
From: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of José Vallet
Sent: Friday, September 29, 2006 5:13 PM
To: Ethernut User Chat (English)
Subject: Re: [En-Nut-Discussion] More clients on the same TCP port

Hello

ZIP wrote:
> Hello,
> 
>  Could you please give me a hint how to implement a server, which serves 
> on the same port for more ethernet clients.

From
http://www.ethernut.de/api/index.html

************************
The order of API calls for TCP servers is

     * NutTcpCreateSocket()
     * NutTcpAccept()
     * NutTcpSend(), NutTcpReceive()
     * NutTcpCloseSocket()

Note, that this differs slightly from the Berkley API, where the initial 
socket is bound to a port and an additional socket is created when a 
connection is accepted. Nut/Net doesn't provide a bind call.
*************************

As far as I understand this, once a server socker accepts one incoming 
connection you cannot use that socket to listen for more incoming 
connections. But I am not an expert here.
> 
> Is it possible to have NutTcpAccept on created socket at the beggining 
> of a thread a then starts new thread for this socket, which receives 
> text commands and proceeds them and may-be send replies ?

I think so, as long as you are able to make the socket visible to the 
new thread. However, as I told you before, I think that that socket will 
not accept any other incoming connection, no matter what thread you are 
using it from.

Please, some guru correct me...
> 
> I need to accept more connections before all the commands are proceeded.

I would use different ports. I ignore other solution here.

> 
> Best Regards
> 
> Petr

Regards,
José



_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion




More information about the En-Nut-Discussion mailing list