Page 1 of 1

[solved] Sockets: reuse receive() w/out creating socket new?

Posted: 27.02.2009, 16:12
by Stuffer
Hey,

I have a problem with using the socket library.
I managed to read from the socket via hook script.

Is there a possibility to reuse a created socket without reopening and reconnecting to the server socket?
What I want to achieve is setting up a socket only once and then connect to the server socket in the first tick by using a global counter.
Afterwards I only want to receive data from the socket for the rest of the time/ ticks.Long story short I want to keep a connection open and reuse it.

When I'm doing sth. like that until now my program is stuck when trying to receive data the second time and doesn't continue. When I set a timeout I get no data from receive() anymore but always a timeout error

So the only way to call receive() more often is to recreate my socket and reconnect to the same host and port again and again in every tick().

Why I'm trying to do this is because if reconnecting with every tick() Celestia seems to get data only about every second. And when I try to move the view (e.g. rotate the earth, ...) the movement is not very fluent.

Do you have experience with displaying not very well while reading data from a socket?

My server is from a simulator software and is able to write the data 25times a second if a client connect()s and receive()s

Re: Sockets: reuse receive() without creating socket new?

Posted: 19.03.2009, 13:02
by Stuffer
I managed to reuse a socket by just creating a server and a connected client once and then receive on this client in an infinity loop.
That way I don't need to recreate the server and don't need to wait until it's unbind to bind on same port again.