Code required for socket emulator free?

Asked By 10 points N/A Posted on -
qa-featured

Hi Experts,

I need a socket code written in C or C++ which helps me in linking connection between two distinguishable emulators on two different computers.

Please help me by sharing socket emulator free source code.

Thanks in advance.

SHARE
Answered By 0 points N/A #167903

Code required for socket emulator free?

qa-featured

Hello,

I have attached a server-side code that establishes connections with, and accepts messages from, clients with select().  I have used port 9999 for listening. You can use any free port. I have not defined functions and have let the main function do all things. Toward the bottom please  have a look at the "for" loop which is a bit large.
 
The code is not for sending data to individual clients from the server. But it is doable if coded. As you can't send data to a client using "select()", you need to do something different. You can send data with a socket "send()", just as the code reads data with "recv()". For example:
 
char *msg = "This is a piece of message.";
int len, bytes_sent;
/*   
Some lines of code to do something
*/
len = strlen(msg);
bytes_sent = send(sockfd, msg, len, 0);
 
To learn more about socket programming here is an excellent website. http://www.beej.us/guide/bgnet/output/html/multipage/index.html
 
Hope it helps.
 
Best Regards,
Parisi

Login/Register to Answer

Related Questions