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. ViPeR

    Brian Palmer Guest

    Two things I'd suggest looking at. See if it works if you use a port >
    1024. (Unix systems traditionally require a program using a
    low-numbered port to have root (== Administrator) privileges). Second,
    make sure that there is no firewall running which is blocking off the
    port. Recent versions of Windows come with their own firewall

    (Disclaimer: I've never used nor seen Windows 2003, and rarely do
    socket work on any versions of Windows with Java).
    Brian Palmer, 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.