Howto: With an Exisitng Connection connect out to another server?

Started by
5 comments, last by Tonic151 21 years, 1 month ago
say i have an connected socket to my server.. how would i take this socket and conenct out to another server?
Advertisement
quote:Original post by Tonic151
how would i take this socket and connect out to another server?

You cannot do this with TCP. With UDP, you could connect() with another server, but the best way would be to use recvfrom() / sentto() and provide the IP info in those calls.

-cb

Multiple connections via single socket is impossible and is a bad design even in terms of logic. Given a socket, the OS would not be able to update the process upon incoming data because the socket is linked to multiple connections.

Kuphryn

I''ll try to explain what i''m doing, I run a Telnet Server, or old Fasion BBS program though Telnet. The Telnet server creates a drop file and passes the socket the handle.

My program (a door Program) then takes this socket handle and can now interact with currect connection. I''m Trying to make my program allow a person to then Telnet back out over the internet. to another telnet server.

Since my socket is already conencted and active. How would i go about passing or taking it and conencting to another telnet server then routing the input/output back to the original instance.

I was wondering can i use the same socket handle or do i need to create another one, really what i''m asking is how i can go about this.. i''ve been searching around but it hard to find specific stuff about what i''m looking to do.. Any help is much apprecieated! I''ve some other programs that do excatly this. only most of them are very old.. and i wanted to make my own. Any help would be much apprecieated

quote:Original post by Tonic151
Since my socket is already conencted and active. How would i go about passing or taking it and conencting to another telnet server then routing the input/output back to the original instance.


You would do exactly that: establish a connection to another server via a new socket and either 1) enter a loop of read-from-new-connection and write-to-old-connection until either connection is closed, 2) use asynchronous sockets and pass data on notification messages, or 3) create a completion port for the new connection and write data to the old connection within the callback function. Keep in mind that even firewalls, whose job is to basically route data (after verification, etc.), are forced to keep more than one connection open (one to the internal, requesting client, and another to the external host).

RapscallionGL - arriving soon.
________________________________________________"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C
i did a little rewritting, and changed it from a winapp to a console, and fixed a few other things.. I''m using threads that listen to each socket in a loop on recv and send, to converse between the sockets. everything is running great. And i Can Telnet out once connected.

only 1 problem now.. I seem to get extra characters sometimes between the recv and send with the data being sent the screen..

I Zeromem all the buffers to 0 before i call the recv.. but i don''t know why i''m getting these extra characters on the screen.. i don''t seem to have as much of a problem when i telnet to myself. but when i go out on the internet.. i notice a lot more...

any ideas?
quote:Original post by Tonic151 I seem to get extra characters sometimes between the recv and send with the data being sent the screen..

Either OOB data or simply CR/LF/TAB chars being interpreted. Just a guess...

-cb

This topic is closed to new replies.

Advertisement