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();
}
}
}
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();
}
}
}