Java Socket Programming in Windows 2003

V

ViPeR

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:

CLIENT SIDE:

import java.net.*;
import java.io.*;

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

String server = "10.0.0.250";
int port = 7;

Socket sock = new Socket(server, port);

OutputStream out = sock.getOutputStream();

String message = "Test";

byte[] byteBuffer = message.getBytes();

out.write(byteBuffer);
}
}



SERVER SIDE:

import java.net.*;
import java.io.*;

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];

for(;;){
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 = in.read(byteBuffer)) != -1)
out.write(byteBuffer, 0, recvMsgSize);

clntSock.close();
}
}
}
 
J

Joseph Dionne

First the obvious questions;

1) exactly how is it failing?
2) your server, on the win2003 system, is IP address 10.0.0.250
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?
 
V

ViPeR

My server is on Windows 2003. The IP is 10.0.0.250. 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.






Joseph Dionne said:
First the obvious questions;

1) exactly how is it failing?
2) your server, on the win2003 system, is IP address 10.0.0.250
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?
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:

CLIENT SIDE:

import java.net.*;
import java.io.*;

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

String server = "10.0.0.250";
int port = 7;

Socket sock = new Socket(server, port);

OutputStream out = sock.getOutputStream();

String message = "Test";

byte[] byteBuffer = message.getBytes();

out.write(byteBuffer);
}
}



SERVER SIDE:

import java.net.*;
import java.io.*;

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];

for(;;){
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 = in.read(byteBuffer)) != -1)
out.write(byteBuffer, 0, recvMsgSize);

clntSock.close();
}
}
}
 
C

Cyrille \cns\ Szymanski

My server is on Windows 2003. The IP is 10.0.0.250. 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.

Try using port 10007 (which is > 1024).
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.

What exception does that raise ? Where ?
 
J

Joseph Dionne

I'll assume Java ServerSocket is NOT giving you an exception?
My server is on Windows 2003. The IP is 10.0.0.250. 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.






Joseph Dionne said:
First the obvious questions;

1) exactly how is it failing?
2) your server, on the win2003 system, is IP address 10.0.0.250
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?
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:

CLIENT SIDE:

import java.net.*;
import java.io.*;

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

String server = "10.0.0.250";
int port = 7;

Socket sock = new Socket(server, port);

OutputStream out = sock.getOutputStream();

String message = "Test";

byte[] byteBuffer = message.getBytes();

out.write(byteBuffer);
}
}



SERVER SIDE:

import java.net.*;
import java.io.*;

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];

for(;;){
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 = in.read(byteBuffer)) != -1)
out.write(byteBuffer, 0, recvMsgSize);

clntSock.close();
}
}
}
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top