N/APosted on - 02/10/2013
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.
Code required for socket emulator free?
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);
Hope it helps.