How to transfer the following JAVA codes to C#?

  • Thread starter fAnSKyer/C# newbie
  • Start date
F

fAnSKyer/C# newbie

private void startupServer() {
try {
serverscoket = new ServerSocket(Listener.PORTNUMBER);
SERVER_ON = true;
} catch (IOException e1) {
e1.printStackTrace();
}
}

public void run() {
while (SERVER_ON) {
establishConnection();
while (CONNECTION) {
try {
message = null;
message = inputBuffer.readLine();
}



------------------------------------------------
My approach is
try
{
TcpClient tcpClient =new TcpClient ("localhost",
9001);//connect to the server
NetworkStream netStream = tcpClient.GetStream();//
read the stream
StreamReader sr = new StreamReader(netStream);//
streamreader
while (tcpClient.Connected)
{
String temp = sr.ReadLine();
Log.Text += temp + ".\r\n";


However, mine doesn't work and it stuck at
String temp = sr.ReadLine();


Can anybody give me an idea? or another way to do the same thing as
the java code do?

Thanks a lot
 
G

Guest

fAnSKyer/C# newbie said:
private void startupServer() {
try {
serverscoket = new ServerSocket(Listener.PORTNUMBER);
SERVER_ON = true;
} catch (IOException e1) {
e1.printStackTrace();
}
}

public void run() {
while (SERVER_ON) {
establishConnection();
while (CONNECTION) {
try {
message = null;
message = inputBuffer.readLine();
}



------------------------------------------------
My approach is
try
{
TcpClient tcpClient =new TcpClient ("localhost",
9001);//connect to the server
NetworkStream netStream = tcpClient.GetStream();//
read the stream
StreamReader sr = new StreamReader(netStream);//
streamreader
while (tcpClient.Connected)
{
String temp = sr.ReadLine();
Log.Text += temp + ".\r\n";


However, mine doesn't work and it stuck at
String temp = sr.ReadLine();

Can anybody give me an idea? or another way to do the same thing as
the java code do?

ServerSocket should be TcpListener and not TcpClient !

Arne
 

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

Top