Probem with Linux Socket and Windows client
I'm learning how to write and use sockets following guide of Nathan Yocom's book: "The Definitive Guide to Linux Network Programming".
I'm working in a little application which uses Yocom's methodology to build a listening socket for multiple clients connections using fork system call. Socket works just well as long as I use a Linux client too. If client is a linux box, there's no problem at all. But there's a weird behaviour when I connect to the Linux server socket from a windows box. I do telnet IP_OF_HOST 1972 and as long as I type any character socket disconnect the client. I didn't find any advince within book related to windows client. Does anybody knows what could be wrong? Code:
#include <stdio.h> |
For a start add error-checks after accept, recv and send
|
My socket programming is very rusty (and therefore I might be fully on the wrong track) and I don't have a linux box at hand for testing.
If I look at your code, you close the connection and exit the child when something is received. That can be either a single character or a full string of multiple of characters. But once received, it will exit the child. My guess is that the telnet application in windows sends a single character at a time and therefor after receiving it your program will stop while the linux version will only send after you've pressed <enter>. Simplest check to see if I'm on the right track would be to print the number of characters received. Solution can be to wait for <enter> (<CR> and/or <LF>) before you close the connection and exit. Good luck. |
Thanks fellows for your help.
Wim, I think you are right. I tried again and telnet client in windows behaves different from linux version. I tried the same socket using netcat for windows and that way works the same way as nc for linux. I'll do some more testing and if I found something interesting I'll post again. Regards, Matías Quote:
|
I found windows' telnet client sends new line character after every single character.
Don't now the reason and if that behavour is configurable... |
Quote:
Launch the Windows telnet application, and then enter the command 'send'. Then try to connect your your Linux server to send data. Code:
> telnet |
DWhitney67, thanks! You were pretty pretty close.
Following your tip I did, with windows' telnet client: Code:
> telnet IP_OF_SERVER_HOST PORT Regards, Matías |
All times are GMT -5. The time now is 03:47 PM. |