Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple connections using TServerSocket 1

Status
Not open for further replies.

hennep

Programmer
Dec 10, 2000
429
I want to create a program that can handle multiple connections using th TServerSocket and TClientSocket.
I have already had a look at the chat example in the cbuilder examples directory but it does not solve my problem.
When I connect to the TServerSocket with two telnet sessions, how can I send the response to the correct telnet session ?
 
On each Connection you can create a new Handle of the socket and handle the functionality in a new thread.



hnd
hasso55@yahoo.com

 
Do you have a code snippet, or a link to an example on the net ?
 
Ok I have an example without TServersocket because i am used to do it that way. Originally this routine was used in an Unix environment. It is not yet prepared for posting here. in a few days i'll create a FAQ here.

The general way is that:
1. Create a Server socket
2. Use the accept function to create a new Handle
3. pass this Handle to a new thread which does the processing.
4. go back to 2.



hnd
hasso55@yahoo.com

 
I was hoping I could do without a lot of code.
I made a program in vb6 to tunnel the nntp protocol through telnet. It was an option to read news groups behind a companies firewall.
The idea is to rewrite this program in C to get a stand-alone executable. When I cannot do it without a control and standard methods and events it might get a bit too difficult for me.
 
This code I am using is basically C-Code and it doesn't use
TServer/TclientSocket but therefore it could be used in different environments the Sources for Client and Server are posted in the faq (Socket-Programming)

hnd
hasso55@yahoo.com

 
thanks hnd,

is there anything important in the include file tcp_accept.h in the server faq ?


hennie
 
No it is empty. It had been assigned by C-Builder

hnd
hasso55@yahoo.com

 
hi hnd,

I could make the server work. I made a program that returns the data it receives, when i create a connection with telnet I can see the characters after I hit the enter key.
It is like you wrote in the faq, it waits for a <CR>.
but when I disconnect the telnet session I want to close the socket, how can I detect a closing socket and how do I use the &quot;closesocket&quot; you mentioned at the end of the server faq ?

thanks,
Hennie
 
Closesocket is a part of the winsock.dll

You can initialize the function in your application like the other DLL functions and call it:
closesocket(fd); fd = socket handle.

This function has not been inserted, because it s part of the user defined thread function, but there will be a comment next days. (thank you)

if you need special functions then you have to modify the netread and/or netwrite function according your requirement.

hnd
hasso55@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top