简体   繁体   中英

Problem connecting a linux server and windows client with sockets

Hello all I am trying to learn more about sockets and how to use them and I have been stuck on an issue for a while now.

I started with Beej's guide to network programming and I made the talker and listener from this page on the linux (Fedora 14) machine I am working on. It works and I can get it to talk to each other.

Then I went on to Windows (7) and worked with this tutorial and got that up and running and can send messages to myself on the windows machine. The only change I really have is that I am using getHostbyAddr and not by name.

It is when I glue the two together that I start to get issues, or rather one issue for now. I am running listener from Beej on the linux machine and I try to have the client from Johnnie send it a message. I get a winsock error 10061 on the windows machine and nothing ever shows up on the linux (not surprisingly). I have tested this with the firewall on the linux and I still get that error.

What can I do to fix this?

Thank you

Edited to add some more info:

When I run tcpdump I get this

[root@localhost ~]# tcpdump tcp port 4950
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
12:08:56.246753 IP TLARGE.WIFI.schoolname.EDU.62394 > hmd46.cs.schoolname.edu.sybasesrvmon: Flags [S], seq 150153995, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
12:08:56.246794 IP hmd46.cs.schoolname.edu.sybasesrvmon > TLARGE.WIFI.schoolname.EDU.62394: Flags [R.], seq 0, ack 150153996, win 0, length 0
12:08:56.746170 IP TLARGE.WIFI.schoolname.EDU.62394 > hmd46.cs.schoolname.edu.sybasesrvmon: Flags [S], seq 150153995, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
12:08:56.746221 IP hmd46.cs.schoolname.edu.sybasesrvmon > TLARGE.WIFI.schoolname.EDU.62394: Flags [R.], seq 0, ack 1, win 0, length 0
12:08:57.246138 IP TLARGE.WIFI.schoolname.EDU.62394 > hmd46.cs.schoolname.edu.sybasesrvmon: Flags [S], seq 150153995, win 8192, options [mss 1460,nop,nop,sackOK], length 0
12:08:57.246185 IP hmd46.cs.schoolname.edu.sybasesrvmon > TONJELARGE.WIFI.schoolname.EDU.62394: Flags [R.], seq 0, ack 1, win 0, length 0
^C
6 packets captured
6 packets received by filter
0 packets dropped by kernel

Running netstat gives me this:

[root@localhost ~]# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      PID/Program name   
tcp        0      0 0.0.0.0:58661               0.0.0.0:*                   LISTEN      1083/rpc.statd      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1013/rpcbind        
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1265/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1148/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1554/sendmail: acce
tcp        0      0 :::56315                    :::*                        LISTEN      1083/rpc.statd      
tcp        0      0 :::111                      :::*                        LISTEN      1013/rpcbind        
tcp        0      0 :::22                       :::*                        LISTEN      1265/sshd            
tcp        0      0 ::1:631                     :::*                        LISTEN      1148/cupsd     

Both of these were from the linux machine

Error 10061 means WSAECONNREFUSED . In the link you posted I see the client is using port 80. Are you sure you modified it to 4950 ?

Something is definitely getting through to the server, otherwise it wouldn't send you the "I don't like you" RST (that's what connection refused means: not only does it refuse your connection, to add insult to injury it's telling you).

EDIT 1

From the netstat output it seems nobody is listening on 4950 .

EDIT 2

I finally brought myself to read that beej stuff (to be honest I always considered his tutorials the worst). Didn't this set off any alarm ? You're creating a udp socket, that's why nobody is listening in TCP 4950 , that's why you can't connect.

hints.ai_socktype = SOCK_DGRAM;

You have two options:

  • Use a UDP socket in the windows side
  • Change the code on the server side to use TCP .

The server code as it stands isn't suitable for TCP ( recvfrom and all that stuff) but should be easily adapted).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM