Hey Dudes,
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:
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!";
}
Last edited by Daemon; 03-13-2010 at 05:02 PM.
I've never tried to create server client application, using C# and .net. Only using C, console application.
Hope the following links help
Page 2 - Socket Programming in C# - Part I
Socket Programming in C#
Thx for reply, but i'm really stuck on this.
i read several tutorials and the msdn-library and i really think it should work and it does work on the same machine. I just need someone who's in this socket programming with c#.
Last edited by Daemon; 03-14-2010 at 08:34 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks