my first post so pls be kind :).
Started few days ago with C# and .NET using Visual Studio C# Express 2008.
In school we are coding in Java and started socket-programming but i wanted to do something new and fresh so decided to take a look at C#.
And having a try on a simple chat using TCP sockets.
Now about my Problem:
I don't know why my program doesn't connect to itself at another PC in my House's LAN, could be about my PCs (Firewall etc.) but i want to elimate the possibility of a programming mistake.
However It DOES connect and i can chat when i start 2 instances on the same PC and parameters are "127.0.0.1" and e.g. "5221".
Feel free to ask and thanks in advance.
Here's the relevant Code:
static Socket Socket;
internal static String connect(string sIP, string sPort)
{
try
{
IPAddress IP = IPAddress.Parse(sIP);
Int32 Port = Convert.ToInt32(sPort);
IPEndPoint Endpoint = new IPEndPoint(IP, Port);
Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Socket.Connect(Endpoint);
}
catch (Exception e)
{
throw e;
}
return "Status: Connected!";
}
internal static String listen(string sIP, string sPort)
{
try
{
IPAddress IP = IPAddress.Parse(sIP);
Int32 Port = Convert.ToInt32(sPort);
IPEndPoint Endpoint = new IPEndPoint(IP, Port);
Socket ListeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
ListeningSocket.Bind(Endpoint);
ListeningSocket.Listen(1);
Socket = ListeningSocket.Accept();
ListeningSocket.Close();
}
catch (Exception e)
{
throw e;
}
return "Status: Connected!";
}
Edited by Daemon, 13 March 2010 - 05:02 PM.


Sign In
Create Account

Back to top









