• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Evan 1 · Jul 16, 2010 at 05:39 PM · networkingsocket

Unity3D and Sockets - C#

I'm just curious if it is possible to have custom socket networking with Unity3D? I just want to confirm.

I don't want to use the Unity provided network functions.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by Cyclops · Jul 16, 2010 at 07:00 PM

Here are two links I found that might be useful:

TCP/IP Client-Server Basics and Sockets in C#

and some sample code I wrote in another answer: TCP Client code

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image g-pechorin · Jun 10, 2015 at 02:09 PM 0
Share

Wiki has moved? http://wiki.unity3d.com/wiki/index.php?title=Simple_TCP/IP_Client_-_Server

avatar image Bunny83 · Jun 10, 2015 at 02:25 PM 1
Share

@g-pechorin: Yes, in the beginning the wiki was a community project which got integrated into the Unity website itself. For quite some time there was an URL redirect to the new URL but finally it seems to be gone for good.

I've fixed the link in the answer, thanks.

avatar image
4

Answer by Mike 3 · Jul 16, 2010 at 05:56 PM

It is - you can use the standard .NET sockets

Try checking TcpClient in the MSDN reference: http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx

There are other ways to go about it, but that is a good enough starting point

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Timurov · Oct 15, 2012 at 01:37 PM 0
Share

ok true way, but how to implement it in Unity3D?

avatar image
2

Answer by Bilelmnasser · Nov 23, 2016 at 11:10 AM

start with Microsoft MSDN , i recommend googling the internet tutorials too : MSDN C# Sockets Programming

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lertulo · Mar 07, 2017 at 08:18 AM 0
Share

Yeah, System.Net.Sockets works very well--right up until you realize you can't build for the windows store if you use sockets or threads. :(

avatar image
1

Answer by Masoud_A · Oct 23, 2017 at 04:33 PM

This question is for a long time ago, but if anyone else is wondering about using c# sockets for real-time communications in Unity:

Although it has some difficulties like threading(Unity is single thread) but it's possible.


If you are interested, I have developed a Unity package which has necessary classes for establishing UDP connections and some working examples here.

Briefly it creates two threads for send & receive, properly lock's thread's access to shared resources and provides queues and methods for sending and receiving packets. i have tested it on Windows & Android.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vivek_unity931 · Dec 20, 2019 at 06:40 AM 0
Share

Hi, Thanks for the package. I am trying to use it. In my case, I am using it to send message from one android device to another android device. Basically, just a small text message with some information.

Both device should be able to send and receive. Can you guide me how to use your functions to send a message to the other android device.

avatar image
0

Answer by Ghopper21 · Oct 15, 2012 at 03:09 PM

Check out the video of the "Unity, Network Code, and You" talk from Unite '12. The video archive is here. (Oddly, you can't link directly to the individual video.) The talk outlines 4 ways to do networking in Unity, including sockets.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Can we use Unitys LLAPI to establish a socket connect with a server? 1 Answer

Networking error CreateSocketOrThreadFailure 0 Answers

Socket networking performance tips sought 1 Answer

WebGL sockets fails: Attempt to send to not connected connection 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges