PDA

View Full Version : Any easy to use net library?



Darkhog
03-06-2013, 06:51 AM
I need some noob-friendly network library. One that would do most of hard stuff like making connection and resending UDP packets if it is UDP connection, leaving only sending actual network messages to programmer.

So I could write (in pseudocode) something similar to this:

TCPconnection:=connect_tcp(ip_or_url,port);
UDPconnection:=connect_udp(ip_or_url,port2);
SendString_tcp("Hai, I'm TCP packet!");
SendString_udp("Hai, I'm UDP packet!");
closeTCP(TCPconnection);
closeUDP(UDPconnection);

and from server side

TCPconnection:=connect_tcp(ip_or_url,port);
UDPconnection:=connect_udp(ip_or_url,port2);
while (tcpPacketsInQueue(TCPConnection)) do begin
packet:=GetTCPPacket;
writeln(packet.value);
end;
while (udpPacketsInQueue(UDPConnection)) do begin
packet:=GetUDPPacket;
writeln(packet.value); //packet.value would be variant.
end;
closeTCP(TCPconnection);
closeUDP(UDPconnection);

User137
03-06-2013, 11:15 AM
That is what nxPascal (https://code.google.com/p/nxpascal/) network class is made for. I needed solution that works both on Delphi and Lazarus, so i went with underlying synapse library. There's demo with my engine that can switch between TCP/UDP mode on the fly, and send/receive text and binary messages. They are very easy to use classes.

As far as its testing goes, i have a small game of top-down view ships, controlled with keys. On my local computer i can start over 4 windows of it, and all the ships move in perfect sync on all game windows. There was noticable lag with international TCP connection, but i suspect i didn't do necessary lag predictions or something. But that's game mechanics, not engine's fault. I should still do a filetransfer test sometime to be sure it's working without error.

Additionally couple packets are sent at first to boot all unwanted connections, kind of authentication to network. Second feature is that you can mask-encrypt all data that is sent. It is very fast xor-operation.

Darkhog
03-06-2013, 12:41 PM
Will it work without rest of nxPascal? I prefer Allegro for doing most of things and would use only network bits of nxPascal - I don't want to bring any unnecessary code into my game.

User137
03-06-2013, 01:26 PM
Yes, i tried to make everything modular. nxNetwork is standalone, using only synapse
https://code.google.com/p/nxpascal/source/browse/trunk/src/nxNetwork.pas

uses {$IFDEF UNIX}cthreads,{$ENDIF}
Classes, SysUtils, synsock, blcksock;
...
(and uses Math; for implementation)
More testing for it would be welcome.

laggyluk
03-06-2013, 02:00 PM
i'm using lnet, not sure if it's 'easy' yet