Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-06 Thread FG via Digitalmars-d-learn
On 2015-02-06 at 05:17, Gan wrote: Oh sweet. Though if one message length is off by even 1 byte, then all future messages get corrupted? Yes, but you can easily detect that by adding a magic number and packet checksum to the header.

Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Andre Kostur via Digitalmars-d-learn
On 2015-02-05, 8:17 PM, Gan wrote: On Friday, 6 February 2015 at 01:36:17 UTC, Mike Parker wrote: On 2/6/2015 9:50 AM, Gan wrote: On Friday, 6 February 2015 at 00:35:12 UTC, Adam D. Ruppe wrote: On Friday, 6 February 2015 at 00:31:37 UTC, Gan wrote: Or am I misunderstanding the receive functi

Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Gan via Digitalmars-d-learn
On Friday, 6 February 2015 at 01:36:17 UTC, Mike Parker wrote: On 2/6/2015 9:50 AM, Gan wrote: On Friday, 6 February 2015 at 00:35:12 UTC, Adam D. Ruppe wrote: On Friday, 6 February 2015 at 00:31:37 UTC, Gan wrote: Or am I misunderstanding the receive function? Does it send whole messages or

Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Mike Parker via Digitalmars-d-learn
On 2/6/2015 9:50 AM, Gan wrote: On Friday, 6 February 2015 at 00:35:12 UTC, Adam D. Ruppe wrote: On Friday, 6 February 2015 at 00:31:37 UTC, Gan wrote: Or am I misunderstanding the receive function? Does it send whole messages or just message chunks? It sends as much as it can when you call i

Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 February 2015 at 00:50:43 UTC, Gan wrote: How can you distinguish between different packets that get sent? Won't they all be merged to a giant blob of data? Yeah, that's normal in TCP though, because it is a stream oriented protocol. You could add stuff to your data indicating me

Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Gan via Digitalmars-d-learn
On Friday, 6 February 2015 at 00:35:12 UTC, Adam D. Ruppe wrote: On Friday, 6 February 2015 at 00:31:37 UTC, Gan wrote: Or am I misunderstanding the receive function? Does it send whole messages or just message chunks? It sends as much as it can when you call it. So if there's only 12 bytes a

Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 February 2015 at 00:31:37 UTC, Gan wrote: Or am I misunderstanding the receive function? Does it send whole messages or just message chunks? It sends as much as it can when you call it. So if there's only 12 bytes available when you send it with a 4096 buffer, it will fill the fi

Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Gan via Digitalmars-d-learn
On Friday, 6 February 2015 at 00:28:00 UTC, Gan wrote: On Friday, 6 February 2015 at 00:24:54 UTC, Adam D. Ruppe wrote: On Friday, 6 February 2015 at 00:15:15 UTC, Gan wrote: ubyte[] buf = new ubyte[](0); This is your problem: receive fills a preexisting buffer, and you alloc

Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Gan via Digitalmars-d-learn
On Friday, 6 February 2015 at 00:24:54 UTC, Adam D. Ruppe wrote: On Friday, 6 February 2015 at 00:15:15 UTC, Gan wrote: ubyte[] buf = new ubyte[](0); This is your problem: receive fills a preexisting buffer, and you allocated zero bytes for it to fill, so it can't give you an

Re: Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 February 2015 at 00:15:15 UTC, Gan wrote: ubyte[] buf = new ubyte[](0); This is your problem: receive fills a preexisting buffer, and you allocated zero bytes for it to fill, so it can't give you anything. Give it a bigger buffer, I like to use 4096, and it will

Trying to make a TCP server, client connects and disconnects immediately

2015-02-05 Thread Gan via Digitalmars-d-learn
I managed to get the client to connect but immediately on the server side, this happens: long length = player.playerSocket.receive(buf); if (length == 0) { //No longer connected player.playerSocket.shutdown(SocketShutdown.BOTH); pla