Networking problem
Author |
Message |
davidkey
|
Posted: Sun Mar 25, 2012 7:59 pm Post subject: Networking problem |
|
|
What is it you are trying to achieve?
Stop error from happening
What is the problem you are having?
I'm getting an error when a Turing program connects to my multi client-server (still working on it).
It crashes giving me "I/O attempted on unopened stream number - 10. Open failed with message 'Net Error. Window Socket Library Error #10048'."
I used the NetChat program as a client/session. when connected, it shows "127.0.0.1 Joined the server" but right after my server crash.
Describe what you have tried to solve this problem
tried researching Window Socket Library Error #10048, tells me something about IP/port already used, don't have 2 computers so I don't know if the problem is running client and server on same computer.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
var window_ 2 : int := Window.Open ("title:Rcon")
var window_ 1 : int := Window.Open ("title:Server Window")
const max_connection : int := 16
var port : int
var stream : int
var address : array 1 .. max_connection of string
var connected : array 1 .. max_connection of boolean := init (
false, false, false, false,
false, false, false, false,
false, false, false, false,
false, false, false, false)
process Welcome
put : stream, "<server> Welcome to server"
end Welcome
process send_server
var input : string
loop
Window.Select (window_ 2)
get input
Window.Select (window_ 1)
put "<server> ", input
for a : 1 .. 16
if connected (a ) = true then
put : stream, "<server> ", input
end if
end for
end loop
end send_server
process Find
for a : 1 .. max_connection
stream := Net.WaitForConnection (port, address (a ))
put : stream, "<server> ", address (a ), " has joined server"
put address (a ), " has joined the server"
connected (a ) := true
fork Welcome
end for
end Find
Window.Select (window_ 1)
put "Enter Port: " ..
get port
put "Welcome"
put "running on:"
put "IP: ", Net.LocalAddress
put "Port: ", port
fork Find
fork send_server
|
Please specify what version of Turing you are using
4.1 (4.1.1 can't compile) |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
crossley7
|
Posted: Sun Mar 25, 2012 10:02 pm Post subject: RE:Networking problem |
|
|
I don't know much about coding to connect to a network, but after starting to learn a bit of PHP this summer, I would recommend you look at which port is being used for each thing and then possibly switch the server to using some random port instead of the one it currently uses which I'm guessing would be 80 since that is fairly standard. Hope that helps. |
|
|
|
|
 |
DemonWasp
|
Posted: Mon Mar 26, 2012 1:06 am Post subject: RE:Networking problem |
|
|
Turing is actually really dumb about handling connections. When you complete a handshake, your server should be able to immediately 'listen' to that same port again, while continuing to talk on the existing connections.
Turing can't do that. You will have to listen on a different port for each connection. |
|
|
|
|
 |
Tony

|
Posted: Mon Mar 26, 2012 1:32 am Post subject: Re: RE:Networking problem |
|
|
DemonWasp @ Mon Mar 26, 2012 1:06 am wrote: When you complete a handshake, your server should be able to immediately 'listen' to that same port again, while continuing to talk on the existing connections.
Sure it can. You just have to make sure that at the end of a handshake the server closes the connection, to free up the port to listen to the next incoming message. A typical setup would be:
- client requests next available port
- server starts a new listener on an available port
- server replies with newly opened port
- server terminates the connection with a client
- server starts listening for next request on known port
- client establishes new connection on a port that was allocated for it |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
davidkey
|
Posted: Mon Mar 26, 2012 2:31 pm Post subject: Re: Networking problem |
|
|
well i think i found the problem, in process Find, i put 1 stream and multiple addresses, i have now made an array for stream (1 .. max_connection) and seems to work now |
|
|
|
|
 |
davidkey
|
Posted: Mon Mar 26, 2012 2:35 pm Post subject: Re: Networking problem |
|
|
nvm, there was another error blocking it |
|
|
|
|
 |
davidkey
|
Posted: Mon Mar 26, 2012 3:04 pm Post subject: Re: RE:Networking problem |
|
|
Tony @ Mon Mar 26, 2012 1:32 am wrote: DemonWasp @ Mon Mar 26, 2012 1:06 am wrote: When you complete a handshake, your server should be able to immediately 'listen' to that same port again, while continuing to talk on the existing connections.
Sure it can. You just have to make sure that at the end of a handshake the server closes the connection, to free up the port to listen to the next incoming message. A typical setup would be:
- client requests next available port
- server starts a new listener on an available port
- server replies with newly opened port
- server terminates the connection with a client
- server starts listening for next request on known port
- client establishes new connection on a port that was allocated for it
how do i check if connection ended, or do i end it with Net.CloseConnection if client doesn't respond |
|
|
|
|
 |
Tony

|
Posted: Mon Mar 26, 2012 4:05 pm Post subject: RE:Networking problem |
|
|
For that common port, you'd want to close the connection ASAP, to free it up for the next request. Server throws a response into the pipe and closes it right away. The client can deal with the rest. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Sponsor Sponsor

|
|
 |
|
|