Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - CoderUK

Pages: [1]
1
Network / Re: [SMFL 2] Using TcpListener
« on: April 26, 2013, 06:05:48 pm »
I meant Socket.Done (Also = 0 in the Status enum). Anywho, got it working now anyway.

2
Network / Re: [SMFL 2] Using TcpListener
« on: April 26, 2013, 05:46:16 pm »
Ok, so am I right in thinking that we want to keep listening until it returns 0 (Socket has been sent or received). Once listen returns 0, then we send/receive our data?

3
Network / [SMFL 2] Using TcpListener (FIXED)
« on: April 26, 2013, 05:02:21 pm »
Hi guys.

I'm trying to use the network module of the 2.0 rc to create a simple Server/Client that can send and receive some basic data. I've read through the tutorial and searched the forum best I can, but I can't find anything similar to the problem. First off, I'll post some code snips.

Server code:
Code: [Select]
TcpListener Host;
if(!Host.listen(50000))
return;

TcpSocket socket;
Host.accept(socket);
cout << "New Client Connected: " << socket.getRemoteAddress() << endl;
char ToSend[] = "Success";
socket.send(ToSend, sizeof(ToSend));
cout << "Message sent to client : \"" << ToSend << "\"" << endl;

Client code:
Code: [Select]
TcpSocket Client;
Client.setBlocking(false);
if(Client.connect("localhost", 50000))
        return;
char Message[128];
size_t Received;
Client.receive(Message, sizeof(Message), Received);
cout << "Message received! = \"" << Message << "\"" << endl;

char ToSend[] = "HELLOOOOOOOO";
Client.send(ToSend, sizeof(ToSend));
cout << "Message sent to server : \"" << ToSend << "\"" << endl;

Client.disconnect();

Basically, what happens is the code just hits the return and from what I can tell stops listening (Neglected to give its own thread, so if its listening it causes my UI to lock up atm). Sorry, about the pretty amateurish post,  new to C++/Networking

Pages: [1]