Thread: Sockets
View Single Post
Old 08-19-2004, 11:59 AM   #3
Razzer
New Member
 
Join Date: Jan 2003
Posts: 3
Razzer is on a distinguished road
The simplest would just be a linear socket pattern. It roughly goes something like this

Create server socket (somewhat like you have)
Loop while game is running
Check sockets (look up select())
If new connection is waiting, accept connection
Read new data, parse, and send output.
End loop

Something similar to that pattern. Multithreading might be a challenge that you might not want to take if you don't fully understand BSD sockets. Using asynchronous socket on a TCP stream is unwise, so scratch that option.

It is a bit of a hack. The second paramenter of bind() takes a struct sockaddr pointer. In order for many different socket family and types to be used, different structures (like sockaddr_in) need to be cast to a struct sockaddr pointer.

[code] service.sin_addr.s_addr = inet_addr("127.0.0.1");[/quote]

Instead of inet_addr("127.0.0.1"), you'd probably be better off with INADDR_ANY.

[code] m_socket = AcceptSocket;[/quote]

You won't want to do this in a real MUD. This reassigned the variable m_socket with AcceptSocket, so it completely loses whatever value it had before. The problem is that the value it had before was the descriptor to the server you had just made, and by the reassignment you have lost the server descriptor.
Razzer is offline   Reply With Quote