Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Nov 19, 2014 at 09:50 AM by Landern for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by chetan-rane · Nov 18, 2014 at 12:29 PM · javascriptnetworkingsocket

Need help - Socket Server always connects to port 80

Hi All,

I am trying to create Socket Server using below code

Update:

 // Server 
 
 void SetupServer()
 {
     try
     {
         IPEndPoint ipEndPoint = new IPEndPoint (IPAddress.Parse("192.168.0.2"), 9093);
         Socket _serverSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     
         _serverSocket.Bind (ipEndPoint);
         _serverSocket.Listen (100);
         
         _serverSocket.BeginAccept (new AsyncCallback (AcceptCallback), null);
     }
     catch (Exception ex)
     {
         Debug.Log (ex.Message());
     }
 }
 
 void AcceptCallback(IAsyncResult ar)
 {
     Socket clientSocket = _serverSocket.EndAccept(ar);
 
     _serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), null);
 
     Debug.Log("Client { " + clientSocket.GetHashCode() + " } Connected...");
 
     clientSocket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(RecieveCallback), clientSocket);
 }
 
 // Client
 void SetupClient()
 {
     try
     {
         IPEndPoint remoteEndPoint = new IPEndPoint (IPAddress.Parse("192.168.0.2"), 9093);
 
         Socket _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 
         _clientSocket.BeginConnect(remoteEndPoint, new AsyncCallback(ConnectCallback), _clientSocket);
     }
     catch (Exception ex)
     {
         Debug.Log (ex.Message());
     }
 }
 
 void ConnectCallback(IAsyncResult ar)
 {
         Socket listener = (Socket)ar.AsyncState;
         Socket handler = listener.EndConnect(ar);
 
         Debug.Log("connected to " + listener.RemoteEndPoint.ToString());
 }

But when i export the build as stand-alone exe and run it on windows machine, it always connects to 192.168.0.2:80 port.

It should connect to port 9093.

Whats wrong i am doing?

Any help would be appreciated.

Comment
Add comment · Show 11
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 Structed · Nov 18, 2014 at 12:44 PM 1
Share

When I use your code, I create a server which listens on Port 9093. I'm missing you client code though. I imagine you mean you client is connecting to your server on a wrong port? Please specify!

avatar image Structed · Nov 18, 2014 at 01:05 PM 1
Share

Can you please post you client code?

Other than that, I can only speculate it's what Harshad$$anonymous$$ said: your firewall may block you port and redirect.

avatar image Structed · Nov 18, 2014 at 02:33 PM 2
Share

Works for me, although I have to say I only tested the code without unity in a console application (due to tim reasons)...

Are you sure, this line works? Socket handler = listener.EndConnect(ar);

It does not return a Socket for me.

avatar image Structed · Nov 18, 2014 at 02:37 PM 1
Share

This is my Solution with your code:

link text

sockettest.zip (77.9 kB)
avatar image Structed · Nov 19, 2014 at 09:04 AM 1
Share

How's your status? Did it work?

Show more comments

2 Replies

  • Sort: 
avatar image
3
Best Answer

Answer by HarshadK · Nov 18, 2014 at 12:49 PM

One probability is that your port 9093 is blocked by your firewall hence it connects to port 80 because it is available?

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
avatar image
1

Answer by chetan-rane · Nov 19, 2014 at 09:39 AM

:D HarshadK.......@Structed: the code is working at my end too...i was digging at wrong place (in my code for 80 port connection) ...the issue was with firewall :) ....anyway thanks for your help....the q's is close we can say :D

Programmer life: if you close one prob...next two are waiting for you....now some brainstroming needed to handle multiple concurrent req...

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 Structed · Nov 19, 2014 at 09:49 AM 2
Share

I'm glad it worked and you figured out what the problem was. Good luck with the new problem ;-)

However, the answer of @Harshad$$anonymous$$ should be promoted to an answer and accepted to give credit where credit is due ;-)

avatar image chetan-rane · Nov 19, 2014 at 10:16 AM 0
Share

Yes Credit goes to Harshad$$anonymous$$....the issue was with firwall....thanks a tone and your ans is accepted

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Socket connection on Android/IOS/Windows 1 Answer

Unity C# Sockets? 2 Answers

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

function OnCollosionEnter problems 1 Answer

Fade in Fade out in unity 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges