Java Socket Programming in Windows 2003

Discussion in 'Java' started by ViPeR, Dec 15, 2003.

  1. ViPeR

    ViPeR Guest

    Hi guys,
    I was wondering if any of you have any problems opening a Java socket
    in Windows 2003. My code works fine in Windows XP, and Windows 9x.

    Is there anything special I need to do in order to get Windows to
    allow me to open a port for me?

    Here is a portion of my code:



    public class TestSocket{
    public static void main(String[] args) throws IOException{

    String server = "";
    int port = 7;

    Socket sock = new Socket(server, port);

    OutputStream out = sock.getOutputStream();

    String message = "Test";

    byte[] byteBuffer = message.getBytes();




    public class TCPEchoServer{

    private static final int BUFSIZE = 32;

    public static void main(String[] args) throws IOException{
    if (args.length != 1)
    throw new IllegalArgumentException("Parameter(s): <Port>");

    int servPort = Integer.parseInt(args[0]);
    ServerSocket servSock = new ServerSocket(servPort);
    int recvMsgSize;
    byte[] byteBuffer = new byte[BUFSIZE];

    Socket clntSock = servSock.accept();
    System.out.println("Handling client at " +
    clntSock.getInetAddress().getHostAddress() +
    " on port " + clntSock.getPort());
    InputStream in = clntSock.getInputStream();
    OutputStream out = clntSock.getOutputStream();

    while((recvMsgSize = != -1)
    out.write(byteBuffer, 0, recvMsgSize);

    ViPeR, Dec 15, 2003
    1. Advertisements

  2. First the obvious questions;

    1) exactly how is it failing?
    2) your server, on the win2003 system, is IP address
    3) your server does not several NICs, and .250 is not the primary
    4) win2003 is not using port 7 for any other application (doubtful)

    After starting you server, does netstat -an show a LISTEN port on 7?
    Joseph Dionne, Dec 15, 2003
    1. Advertisements

  3. ViPeR

    ViPeR Guest

    My server is on Windows 2003. The IP is It does not have
    more than one NIC. It is not using port 7 for anything else. I
    checked Netstat and also did a port scan from another machine to
    double check.

    Windows 2003 fails to open the port. Using the EXACT same program on
    a Windows XP Box, it works. This windows XP box uses the EXACT same
    hardware because it is in a dual boot configuration with Windows 2003.

    Thanks for your help.

    ViPeR, Dec 16, 2003
  4. ViPeR

    Harald Hein Guest

    You did not provide us with any error message. Print out the exception
    and read it.
    Harald Hein, Dec 16, 2003
  5. My server is on Windows 2003. The IP is It does not have
    Try using port 10007 (which is > 1024).
    What exception does that raise ? Where ?
    Cyrille \cns\ Szymanski, Dec 16, 2003
  6. I'll assume Java ServerSocket is NOT giving you an exception?
    Joseph Dionne, Dec 16, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.