简体   繁体   中英

Can't communicate via socket on Mac OS X

I'm working on some software that consists of a server and clients on one machine that communicate via local sockets.

The server (written in Java) opens a java.net.ServerSocket on port 9000, and the clients (in either Java or Python) have to connect to localhost:9000 to communicate.

In Windows and Linux, this works fine. On Mac OS X (10.6, Java 1.6.0), no communication between the server and client occurs even though I don't get any errors. Is there something I need to code differently for Mac or is there a system setting I need to change to make it work?

Python client snippet:

import socket
from re import sub

def main(server_address, port):
    '''
    Connect to the server.
    '''

    rclf = '\r\n'
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect((server_address,port))
    s.send("Version:1.0.0"+rclf)

Maybe this will be helpful for someone as I had very similar issue on Mac OS with Java client not being able to open socket for a Web server (lighttpd serving static file): no firewall running; works in Web browser and with CLI tools ( curl and wget ); same for different, non-standard, free ports. Disabling IPv6 support for the Web server resolved the issue.

What exactly happened is beyond my knowledge but prior to the above mentioned change there were no entries in access log of the Web server for the Java client requests. Also,

80/tcp    open  PORT

wouldn't appear on the nmap localhost listing, although

tcp6       0      0  localhost.PORT         *.*                    LISTEN

appeared on the netstat -a listing.

Configuration:

  • Mac OS: 10.6,
  • Java: 1.6.0_24, tried both x86 and amd64 versions.

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