Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 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

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

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