Client Socket Connection to Java server
bieffe62 at gmail.com
bieffe62 at gmail.com
Fri Jan 16 04:52:49 EST 2009
On 16 Gen, 08:10, TechieInsights <GDoerm... at gmail.com> wrote:
> I am having problems with a socket connection to a Java server. In
> java I just open the socket, pass the length and then pass the bits
> across the socket.
>
> I created a socket object:
>
> import socket
>
> class MySocket:
> def __init__(self, host='localhost', port = 28192, buffsize = 1024):
> socket.setdefaulttimeout(10)
>
> self.host = host
> self.port = port
> self.buffsize = buffsize
> self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> self.socket.connect((host, port))
>
> def send(self, data):
> self.socket.send(data)
>
> def receive(self):
> return self.socket.recv(self.buffsize)
>
> def sendAndReceive(self, data):
> self.send(data)
> return self.receive()
>
> def close(self):
> self.socket.close()
>
> But the java server gives the error:
> WARNING: <Incoming> Message length invalid. Discarding
>
> The data is of type string (xml). Am I doing something wrong? I know
> you have to reverse the bits when communicating from C++ to Java.
> Could this be the problem? I figured it would not because it said the
> length was invalid. I just started looking at python sockets
> tonight... and I don't have a real deep base with socket connections
> as it is... any help would be greatly appreciated.
>
> Greg
What is the server protocol? What are you sending? Saying 'xml' is not
enough to understand the problem ...
byte order could be a problem only if the message include binary
representations
of 2-bytes or 4-bytes integer. With XML this should not be the case
Ciao
----
FB
More information about the Python-list
mailing list