Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Archived

This topic is now archived and is closed to further replies.

  • 0
aquilon

Need help with TCP socket

Question

Hello everybody,

I'm trying to connect my OC's computer to my tcp server with the first example here  http://ocdoc.cil.li/api:internet

local internet = require("internet")  
local handle = internet.open("example.com", 1337)  
local data = handle:read(10)------------------------- I REMOVED THIS LINE  
handle:write("1234")  
handle:close()

 

, but my server don't receive the message. I tested with a "real" socket client, and my server is working well. Is the code shown in link is outdated or i'm missing something ?

OC version: 1.7.1.1127-universal

MC version: 1.7.10

Thanks in advance for help

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

Check if you can connect to your server from a remote host. A firewall might be blocking the connection. Keep in mind that your host may be blacklisted in the configuration file by default (if you're trying to connect to localhost, for instance).

Wrap handle:write("1234") into print (like print(handle:write("1234"))) so that if there were any errors, they would be printed, not ignored.

Also, try to os.sleep a while before writing to or reading from the socket. Perhaps the socket doesn't get enough time to establish the connection. Call handle.stream.socket.finishConnect() to check if the socket is connected.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.