network socket help

BlitzMax Forums/BlitzMax Beginners Area/network socket help

Kev(Posted 2006) [#1]
Hi

I have a very basic network server and client using UDP socket's this works fine for testing im simply sending one byte of data from the client to the server so when the server obtains the data it shuts down.

now any ideas on the best way to compress/hold data to be sent to the server the same would be used when reciving data on the client side.

kev


Rck(Posted 2006) [#2]
I used UDP in BlitzPlus but now feel that TCP is more desirable in BlitzMax (I found it easier to identify the sender of packets without having to use recv_from).

I am starting to use sockets in BMAX as well. Compression of data only becomes usefull when your packets become either quite large and/or repetitive in their contents. Let the server manage every connection (in TCP) to other clients by checking each socket for readavail and reading up to a certain number of times per main loop (such as 20 or 1000, depending on the kind of server you're making). Simply define a packet structure and include some kind of data in the beginning of the packet as a header (such as the number of bytes in the rest of the packet and the "type" of packet) along with the rest of the data.


Kev(Posted 2006) [#3]
Hi Rck, Ive modifyed the server and client to use TCP now i do find the TCP sockets to be more usable however sending and reciving data is not possable yet still need to figure out why. CreateSocketStream() opens correctly but when sending data using the client the server always recives zero im still looking into this.

kev


tonyg(Posted 2006) [#4]
Does this help?


Kev(Posted 2006) [#5]
thanks tonyg that does help loads.

kev


Kev(Posted 2006) [#6]
Hi Again

ok i now have a working TCP client and server, the client can connect/re-connect to the server and send its data.

now next question, i think that the client should be-able recive data from the server. is this normal to have 2 way data processing?

and finaly how could i find the millisec from data leaving the server and ariving at the client and vice-versa? is this even nesseray?

o' one more, what information would you recommend to keep track of client connection, for now i have ip-address and ports. im aware username and passwords could also be held and possabley validated before the connection is excepted.

kev


Brendane(Posted 2006) [#7]
Hi,

Yes it is 'normal' for clients to recieve data from the server, it all depends on your application.

Your query about timings : Not necessary (unless you really want it) but TCP is guaranteed to reassemble individual packets into the correct order before you get to pull them from the buffer. (I presume this is why you are asking).

Your query about users/passwords : This is a matter of you designing your own protocol above TCP. Essentially you should establish a protocol whereby the client is validated by the server, maybe something like this :-

a) client connects to server
b) server responds with a message to request you to log in
c) client sends login details (encypted)
d) server validates the login details and either accepts or rejects the client.

The above scenario will require you to implement some kind of state machine for the protocol to work properly.


Kev(Posted 2006) [#8]
thanks brendane for clearing these issues up, i intend on wrapping this into a module and making it available to the community adding as much as possable along the way.

kev