hi all - i have a java client and a c# server that need to communicate via sockets; the c# program uses TcpListener and Socket:
(C#)
{...
tcplis = new TcpListener( port );
tcplis.start();
while( true )
{
socket = tcplis.AcceptSocket();
if( socket.Connected == true )
{
// send some stuff
socket.Send(bByteBuffer);
//...
}
// now I need to RECEIVE some
// kind of reply from the Java
// client
socket.Receive(bByteBuffer2); // HERE #1
...}
the Java client looks something like this:
(Java)
{......
jsocket = new Socket( host, port );
jreader = new BufferedReader( new InputStreamReader(
jsocket.getInputStream());
jwriter = new PrintWriter(
jsocket.getOutputStream(),
true );
// read whatever the c# server sends this way:
while( jstring = jreader.readline())
{
if( jstring.compareTo( BYE_STRING )break;
// process input, .....
}
// now the client tries
// to send something to the server
jwriter.println( "Message....." ); // HERE #2
.......
}
well, my problem is that the server to client communication works fine; however, when the c# program gets to the Receive() part (HERE #1), it blocks indefinitely. single stepping through the Java code shows that it hangs there as well (at the jwriter.println() line, see HERE #2 -- it's not able to complete the Send to the server).
clearly, the C# socket does not switch from writing to listening mode for some reason. a socket.Poll( SelectWrite ) returns true. the only way i got it to work is by issuing a socket.Shutdown(Send) in right before HERE #1, but that is not acceptable since the c# will have to send more stuff after it receives the message from the client.
am i missing something there? should the socket in c# be initialized differently? i tried to do a socket.SetSocketOption( AcceptConnection, 1 ) but it returned an error (illegal level or value).
in a different situation, the c# server socket Receives at first just fine from a Java client but then it hangs just the same when trying to Send subsequently.
any ideas? thanks.
(C#)
{...
tcplis = new TcpListener( port );
tcplis.start();
while( true )
{
socket = tcplis.AcceptSocket();
if( socket.Connected == true )
{
// send some stuff
socket.Send(bByteBuffer);
//...
}
// now I need to RECEIVE some
// kind of reply from the Java
// client
socket.Receive(bByteBuffer2); // HERE #1
...}
the Java client looks something like this:
(Java)
{......
jsocket = new Socket( host, port );
jreader = new BufferedReader( new InputStreamReader(
jsocket.getInputStream());
jwriter = new PrintWriter(
jsocket.getOutputStream(),
true );
// read whatever the c# server sends this way:
while( jstring = jreader.readline())
{
if( jstring.compareTo( BYE_STRING )break;
// process input, .....
}
// now the client tries
// to send something to the server
jwriter.println( "Message....." ); // HERE #2
.......
}
well, my problem is that the server to client communication works fine; however, when the c# program gets to the Receive() part (HERE #1), it blocks indefinitely. single stepping through the Java code shows that it hangs there as well (at the jwriter.println() line, see HERE #2 -- it's not able to complete the Send to the server).
clearly, the C# socket does not switch from writing to listening mode for some reason. a socket.Poll( SelectWrite ) returns true. the only way i got it to work is by issuing a socket.Shutdown(Send) in right before HERE #1, but that is not acceptable since the c# will have to send more stuff after it receives the message from the client.
am i missing something there? should the socket in c# be initialized differently? i tried to do a socket.SetSocketOption( AcceptConnection, 1 ) but it returned an error (illegal level or value).
in a different situation, the c# server socket Receives at first just fine from a Java client but then it hangs just the same when trying to Send subsequently.
any ideas? thanks.