Click here to Skip to main content

f_m_g asked:

Open original thread
Hi There,
 
I am writing an service that should be reply some information via TCP.
After starting the service a second PC try to connect with the service.
 
In the OnStart of the service I create an instance of my comunication class with:
 
string urlService = "net.tcp://192.168.10.48:1234/MyService";
 
host = new ServiceHost(typeof(ServicePCBI));
host.Opening += new EventHandler(host_Opening);
host.Opened += new EventHandler(host_Opened);
host.Closing += new EventHandler(host_Closing);
host.Closed += new EventHandler(host_Closed);
 
NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.None);
 
host.AddServiceEndpoint(typeof(IServiceTest), tcpBinding, urlService);
 
host.Open();
 
 
This part of code runs and listen to the port, I write an logfile to check all events and it looks like everything is ok.
I have checked the IP of the service (first I had an wrong IP, but was no big change to correct this).
 
Here one of the tests, that not work
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
IPAddress addr = IPAddress.Parse("192.168.10.48");
IPEndPoint endpoint = new IPEndPoint(addr, 1234);
AddToLogFile("start listen! ");
while (true)
{
     sock.Bind(endpoint);
     sock.Listen(10);
     Socket client = sock.Accept();
     AddToLogFile("Now ok! " + client.LocalEndPoint.ToString());
}
 
Has anyone an idea why I can't connect with the socket in the service?
Thanks
Tags: C#

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100