Server.cs
/*
* Created by SharpDevelop.
* User: Shannon
* Date: 12/26/2011
* Time: 9:32 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Net;
using System.Net.Sockets;
namespace Server
{
class Program
{
public static void Main(string[] args)
{
IPAddress ip = IPAddress.Parse("127.0.0.1");
int port = 2222;
byte[] buffer = new byte[256];
IPEndPoint IPe = new IPEndPoint(ip, port);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Bind(IPe);
sock.Listen(0);
sock.Accept();
sock.Receive(buffer, 256, SocketFlags.None);
sock.Send(buffer, 256, SocketFlags.None);
sock.Close();
}
}
}
Client.cs
/*
* Created by SharpDevelop.
* User: Shannon
* Date: 12/26/2011
* Time: 9:01 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Net.Sockets;
using System.Net;
namespace Client
{
class Program
{
public static void Main(string[] args)
{
IPAddress ip = IPAddress.Parse("127.0.0.1");
int port = 2222;
byte[] buffer = new byte[256];
EndPoint ep = new IPEndPoint(ip, port);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(ep);
byte[] msg = Console.ReadLine(); // Can't convert from byte[] to string, not sure what to do.
sock.Send(msg, 256, SocketFlags.None);
sock.Receive(buffer, 256, SocketFlags.None);
sock.Close();
}
}
}
I'm just having trouble with the input. I've tried to search up client/server examples, but nobody seems to be doing anything similar.

New Topic/Question
Reply



MultiQuote




|