Socket Libraries

Jan 22, 2010 at 12:00am
Hi,

I would like to create a UDP client that connects and sends data to a server

I have two questions.

Will the standard Winsock library be sufficient?

if not, which socket library would you suggest i require ?
Last edited on Jan 24, 2010 at 5:51pm
Jan 22, 2010 at 1:08am
the standard winsock is sufficient...
Jan 22, 2010 at 2:30pm
Thank you for your reply
Last edited on Jan 24, 2010 at 5:51pm
Jan 22, 2010 at 5:24pm
http://www.ragestorm.net/tutorial?id=12 one of those spitted out by google... not the best but ok... i suggest u reading something in the msdn and
http://beej.us/guide/bgnet/output/print/bgnet_A4.pdf
Jan 22, 2010 at 5:31pm
I really like Poco Library. Its cross compatible. And its sockets are wicked easy to use.

http://pocoproject.org/docs/

Even has socketstream to stream copiers or socketstream to std::string copiers.

Quick example (not UDP) of sending / receiving text using strings:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <Poco/Net/StreamSocket.h>
#include <Poco/Net/SocketStream.h>
#include <Poco/Net/SocketAddress.h>
#include <Poco/StreamCopier.h>
#include <Poco/Thread.h>
#include <string>

const char * host = "127.0.0.1";

int main()
{
    std::string outstring;
    Poco::Net::StreamSocket socket(Poco::Net::SocketAddress(host, "5221") );

    Poco::Net::SocketStream ss(socket);

    ss<<"This will get sent to the server!"<<std::endl;
    ss.shutdownsend();

    while (true)
    {
     if (socket.poll(100, SELECT_READ) == true)
    {
          if (Poco::copyToString(ss, outstring) > 0)
          {
              std::cout<<"Received "<<outstring<<" from sever"<<std::endl;
              break;
          }
    }
    Poco::Thread::sleep(100);
    }
    return 0;
}


Note: I didn't compile this. So some tweaking may be necessary. Could even remap std::cout to receive the string stream. I created a simple cout forwarder of TCP/IP using this method. It would buffer up then transmit then rebuffer. Worked pretty well. I remapped the cout to the socketstream
Last edited on Jan 22, 2010 at 5:39pm
Topic archived. No new replies allowed.