Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on communicating unity application with an PC app. Since I doesn't know how socket programming can be implemented in unity.Can anybody please help me in creating a simple small application using TCP socket with unity

share|improve this question

Unity has two different networking subsystems: The old but still available Legacy Networking API and the New UNET Networking API. But both are high-level APIs designed around the Unity engine and don't offer low-level TCP/IP functionality (both are based on UDP). That means you can't use them to interface with something not developed in or specifically for Unity, especially not something which expects a TCP connection.

You can also use the Unity class WWW to interface with programs which use a HTTP-based communication protocol (like SOAP or REST, for example). But this class doesn't provide raw TCP sockets either.

However, nothing stops you from using the standard networking classes available in the .NET framework. Specifically the class Socket or the more high-level class TcpClient and the class NetworkStream are of interest here. Details about how to use the .NET socket classes aren't game-development specific, so you should ask about them on Stackoverflow. By the way: I haven't tried but I can't imagine that this works on platforms which don't have a low-level TCP API, like for example HTML5.

share|improve this answer
    
That's untrue about the new API. They expose functionality to work with the raw sockets (or as close as you can get which I wouldn't consider high level at that point). docs.unity3d.com/Manual/UNetUsingTransport.html It also works with the HTML5 target by using WebSockets, so that's neat. – Coburn Aug 26 '16 at 17:33
    
@Coburn I'm sorry, but you are wrong about that. UNET is based on UDP, not TCP. It doesn't even give you pure UDP, because it adds some TCP-inspired reliability features to it. WebSockets use TCP, but they aren't pure TCP either. They add a lot of framing and masking around it. Why is this nitpicking important? Because the OP wants to interface with an existing TCP application, which requires to accurately implement a TCP-based protocol. – Philipp Aug 26 '16 at 17:56
    
Ah, I must've misread. You're still stuck in Unity's domain if you're using UNet, it's just lower level UNet and not raw sockets. I figured it would be to OPs benefit to know it exists depending on her usecase. – Coburn Aug 26 '16 at 18:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.