Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am trying to use Socket object in my application. The code can simply seen below.
//Using TcpClient Class
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("http://myserver.com", 123);
// we can also say 
tcpClient.Connect(IPAddress.Parse("125.54.10.25"), 123);

//Using Socket Class
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.Connect("http://myserver.com", 123);
//or

client.Connect(IPAddress.Parse("125.54.10.25"), 123);


When using Socket I can't connect to the server over the Internet with such configuration
(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
So, what is the right way of AddressFamily, SocketType and ProtocolType?
Posted
Updated 9-Dec-11 22:50pm
v2

You could try giving a valid IP address:
125.54.10.0.0
is not valid - it has too many number blocks for IPV4 (which has four blocks, "125.54.10.0") or it needs colons for IPV6 (which has six number blocks "125:54:10: 0: 0: 0")
 
Share this answer
 
Comments
adadero 10-Dec-11 4:53am    
I have improved my question, the IP Address has five blocks and now it remains four. With TcpClient I can connect over the internet using a domain name and IPV4. What's the problem with the Socket Object?
client.Connect("http://myserver.com", 123);


try changing this to:

client.Connect("myserver.com", 123);


I don't think that this would prove of any use, its just that there is no need to specify http there when we are explicitly mentioning the port.
 
Share this answer
 
Comments
adadero 11-Dec-11 2:26am    
Thanks for the reply. It's now solved. Thanks for helping me.
Robin Rizvi 11-Dec-11 4:23am    
Happy to help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900