server & client

Discuss any general programming issues here
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

server & client

Post by xabierpayet »

i´m doing a little client that send text messages to a server in a remote machine.
I understand that my client code will be something as....

OpenConnection(1,"realipoftheserver",2550)
ser$=StringRequest("msg","write the msg")
count = SendData(1, ser$)

and the server

CreateServer(1,2550)
function p_....

but, the problem is that i cannot connect to the server, ever hve this error, i try to change ports and turn off the firewall.

Error in line 43 (client.hws): The following network error occurred:
connection refused

someone have any idea about how to solve this problem?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: server & client

Post by airsoftsoftwair »

Can you connect to the server via telnet?
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

Re: server & client

Post by xabierpayet »

i can connect to server via 192.168.1.x and send the text, the problem is with an ip address
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: server & client

Post by airsoftsoftwair »

I don't understand... what do you mean by "the problem is with an ip address"?
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

Re: server & client

Post by xabierpayet »

ok, imagine that i have a server in a computer with the ip 90.123.183.188 and port 2550
and i have this code:

CreateServer(1,2550)
Function p_ConnectFunc(msg)
Switch(msg.action)
Case "OnConnect":
DebugPrint("Connected ")
EndSwitch
EndFunction
InstallEventHandler({OnConnect = p_ConnectFunc})
Repeat
CheckEvent
Forever

is not possible send data to this ip directly from other computer with a different ip? both computers don´t share the same net, a practical example will be (i think), i do a server and you send to me text to my server

my client is this, but i don´t can connect between them

OpenConnection(1,"90.123.183.188",2550)
ser$=StringRequest("msg","write the msg")
count = SendData(1, ser$)
PEB
Posts: 567
Joined: Sun Feb 21, 2010 1:28 am

Re: server & client

Post by PEB »

If I'm understanding you correctly, you are trying to receive a connection from a computer that is not part of your local network (not connected to the same router).
You probably need to set up "port forwarding" in your router settings so that any connection coming from the outside to your router (using your global IP address) can then be directed to your computer attached to the router (using your local IP address).
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

Re: server & client

Post by xabierpayet »

yes, you are understanding it correctly, i open all the router ports and disconnect the firewall, but i don´t can send the data i have ever the same "timeout" error
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

Re: server & client

Post by xabierpayet »

problem solved, thanks PEB and Andreas
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

Re: server & client

Post by xabierpayet »

maybe i found a bug, or i don´t know how use it, check this code

Case "OnConnect":
Print("client id ",msg.serverid)
.....

this code, ever return a table, i cannot have the client id, the "msg.serverid" work fine returning the number, maybe i need use another syntax?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: server & client

Post by airsoftsoftwair »

I'm not exactly sure what your problem is but maybe you're looking for this?

Code: Select all

Case "OnConnect":
	Print("client id", GetLocalIP(msg.clientid))
Here we use GetLocalIP() to get the IP from a network object.
Post Reply