Ronin
Ronin

Reputation: 2077

server in Java, client in C - cannot get the data

I am writing code for tcp-ip server client... the problem I am facing is :: My server is in Java and listening to a port, if anything it found simply it prints what it found.

I have a client in Java and a client in C . When I use my Java client and send String "hello server" - the server finds that and prints that BUT when the C client sends it using the "send" of winsock.h, the Java server gives error on the line :: (I have used Buffereader and readline to get the data from tcp-ip port in Java server)

        commandFromPortal = inFromClient.readLine();

and the errors are ::

           Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at org.snmp4j.NOCAlarmManager.Clientnew.run

What should I do ??? Any suggestion ??

Upvotes: 0

Views: 358

Answers (2)

Kevin
Kevin

Reputation: 56149

It sounds like the socket is buffering when you write to it and the queued data is not being flushed (sent) before you close the socket (you are closing it properly, right?). The fact that it works when you add a newline (\n) seems to confirm this. So you have to flush the buffer on the socket before you close it. I don't work with winsocks, but from this website I gather you should call shutdown(sock,SD_SEND) (if that doesn't work, check the winsock documentation for how to flush the socket buffer).

Upvotes: 1

John Eipe
John Eipe

Reputation: 11256

You need to use a Middleware to introduce transparency.

Middleware frameworks are designed to mask heterogeneity of networks and hardware. Most middleware frameworks also mask heterogeneity of operating systems or programming languages, or both.
A few such as CORBA could be used.

Upvotes: 0

Related Questions