SRL Archive - Research & Development Lounge

Help with sockets


austin2162

2011-08-18 01:25:05

so i dived in to sockets to play with them but i cant figure them out can anyone help me with a server and client setup though sockets

edit: if this doesnt go here move it.

superuser

2011-08-18 02:08:51

From: austin2162
so i dived in to sockets to play with them but i cant figure them out can anyone help me with a server and client setup though sockets

edit: if this doesnt go here move it.


What language? If C++, Boost's ASIO is too cool.

austin2162

2011-08-18 02:12:57

in simba.

Echo_

2011-08-18 09:48:10

Have you read this yet?

austin2162

2011-08-18 12:36:35

i did read that but im still struggling

Wizzup?

2011-08-20 05:15:07

Well, I can't provide you with a fully working example right away. But something to get you started:

SocketClient:

program new;
var sock: integer;
begin
sock := CreateSocket();
ConnectSocket(sock, 'localhost', '9001');

sendsocket(sock, 'hi'#10#13);
closesocket(sock);
end.

Tested with: (run the nc command first, not sure if Windows has something similar)

$ nc -l -p 9001 localhost
hi

E: Netcat for windows: http://joncraton.org/blog/46

Server:

program new;
var
serv, sock: integer;
s, ip, port:string;
begin
serv := CreateSocket();
setsockettimeout(serv, 50000);
BindSocket(serv, '0.0.0.0', '1504');
ListenSocket(serv);;

sock := AcceptSocket(serv);
setsockettimeout(sock, 50000);

writeln(recvsocketstr(sock));
end.

Tested with telnet:
$ telnet localhost 1504
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
HELO
Connection closed by foreign host.

Compiled succesfully in 100 ms.
HELO
Successfully executed.


Hope it helps. I didn't fully figure it out myself yet. Dgby knows a lot more on this.

fiasco1114

2011-09-15 20:41:48

And if you mean player information. Yes, I already have some functions started for it.