1. non-forking TCP-server - what am i doing wrong?
Thank you for reading this! This post is long, because
i need the comp.unix.programmer-folks help, so i am
trying to describe everything in details for you.
I am making a non-commercial multi-player russian card
game. The clients are written in Java and the server
in C and runs on a Linux box, listenning to port 7000.
The communication format between server and clients is:
1st byte: length of unicode string (in Java-chars,
which are 16 bit each)
2nd byte: player number (0, 1 or 2)
3rd byte: some game code, ex. 8 means that the unicode
string contains player address
rest: up to 510 bytes long string (up to 255 chars)
When a new client comes, server NORMALLY sends him his
number (0, 1 or 2) and address (8 means "JOIN"-code), ex:
25 0 8 alex.kawo2.rwth-aachen.de
So here is 25 the length of "alex.kawo2.rwth-aachen.de",
8 means "here goes your address" and 0 is player number.
80% of time it works. Could you please take a look at my
code? I have tried to comment it for you very good and
will answer all your questions on it. The code is at:
THE PROBLEM IS:
Sometimes the server sends to the new player:
0 97 0
And it can happen to 0th, 1st or 2rd newcomer.
For example you can see in the log-file:
Sat Jan 24 03:41:52 1998
new player from alex.kawo2.rwth-aachen.de,
assigning number 0 in game 0
Sat Jan 24 03:57:25 1998
new player from artissimo.edisoft.ru,
assigning number 1 in game 0
Sat Jan 24 03:57:26 1998
disconnecting all players from game 0
Java-client disconnects in next second because player
number (stored in j variable) should be 1 and not 97.
SO MY QUESTIONS ARE:
1) Please look through the server code. Maybe you see
some obvious mistakes?
2) Could be smth wrong with using hptr -> h_name and
inet_ntoa (sin.sin_addr) for getting new address?
3) I am setting alarm before reading and writing, to
prevent somebody for example sending one byte 254
and make my server stop and wait for the never
following 2 + 254 * 2 bytes. So if SIGALRM comes
i close the sockets in game i. Is it okay?
Thank you for ANY ideas!
russkaya literatura v ------ http://www.simplex.ru/lit.html
java preferans ------------ http://www.simplex.ru/pref.html
besplatnye kommercheskie ob'yavleniya http://www.simplex.ru
2. cannot extract program
3. "Novell-like","non-TCP/IP","networking" OS to place Unix
4. Installing a 3com 3c905TX 100mbps???
5. !!DDE->TCP/IP, REAL TIME DATA PUMP, Trans.DDE App.DATA via TCP/IP
6. "load average" in "uptime"
7. Novell, TCP/IP, UNIX
8. lpsched error message
9. How can I made a Linux File-Server (Like Novell NW) with TCP/IP ?
10. Printing over TCP/IP to an Novell-Printer ??????
11. TCP/IP over Novell IPX in Linux
12. DOCS: novell TCP/IP adm.Where?
13. !!DDE->TCP/IP, REAL TIME DATA PUMP, Trans.DDE App.DATA via TCP/IP