.net sockets data transmition using sockets (c#) - c#

I'm trying to transfer some data between android client and .net server.
I used sockets. the client sockets is connected while in the server I get no response.
can anyone please review this code and help me? I'm kind of lost.
my client code:
Socket socket1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
try
{
socket1.Connect(IPAddress.Parse(string_ip), 8080);
if (socket1.Connected)
{
Log("connected");
NetworkStream networkStream1 = new NetworkStream(socket1);
byte[] sendData = new byte[1024];
byte[] recievedData = new byte[1024];
string message = "alon aviv";
sendData = Encoding.UTF8.GetBytes(message);
networkStream1.Write(sendData, 0, sendData.Length);
}
else
{ Log("not connected"); }
}
my server code:
Socket socket1 = new Socket(SocketType.Stream, ProtocolType.IP);
System.Net.IPEndPoint ipEnd = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(string_ip), 8080);
socket1.Bind(ipEnd);
socket1.Listen(1);
socket1.Accept();
if (socket1.Connected)
{
UpdateLogText("socket connected");
NetworkStream networkStream1 = new NetworkStream(socket1);
byte[] recievedData = new byte[1024];
networkStream1.Read(recievedData, 0, recievedData.Length);
string message_recieved = Encoding.ASCII.GetString(recievedData);
UpdateLogText(message_recieved);
}

I also tested your code and it was not working at my side as well. I made some adjustments which do work. Please try:
Client
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
byte[] bytes = new byte[1024];
Socket socket1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
try
{
socket1.Connect(IPAddress.Parse("127.0.0.1"), 8080);
if (socket1.Connected)
{
Console.WriteLine("Connected");
// Encode the data string into a byte array.
byte[] msg = Encoding.ASCII.GetBytes("This is a test<EOF>");
// Send the data through the socket.
int bytesSent = socket1.Send(msg);
// Receive the response from the remote device.
int bytesRec = socket1.Receive(bytes);
Console.WriteLine("Echoed test = {0}",
Encoding.ASCII.GetString(bytes, 0, bytesRec));
// Release the socket.
socket1.Shutdown(SocketShutdown.Both);
socket1.Close();
}
else
{
Console.WriteLine("not connected");
}
Console.ReadLine();
}
catch (Exception e)
{
}
}
}
}
Server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
public static string data = null;
static void Main(string[] args)
{
byte[] bytes = new Byte[1024];
Socket socket1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
System.Net.IPEndPoint ipEnd = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 8080);
// Bind the socket to the local endpoint and
// listen for incoming connections.
try
{
socket1.Bind(ipEnd);
socket1.Listen(10);
// Start listening for connections.
while (true)
{
Console.WriteLine("Waiting for a connection...");
// Program is suspended while waiting for an incoming connection.
Socket handler = socket1.Accept();
data = null;
// An incoming connection needs to be processed.
while (true)
{
bytes = new byte[1024];
int bytesRec = handler.Receive(bytes);
data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
if (data.IndexOf("<EOF>") > -1)
{
break;
}
}
// Show the data on the console.
Console.WriteLine("Text received : {0}", data);
// Echo the data back to the client.
byte[] msg = Encoding.ASCII.GetBytes(data);
handler.Send(msg);
handler.Shutdown(SocketShutdown.Both);
handler.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Console.ReadLine();
}
}
}

Related

TCP/IP Connection with Multiple Threads Speaking for Chat Application

i have a TCP Chat Server code sample like this, it creates multiple threads correctly, but it doesn't send the message to all threads. I want the message to be sent accross all threads, like a group chat. Can you help me?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Threading;
class NewClient
{
public Socket newServerSocket;
public NewClient(Socket client)
{
this.newServerSocket = client;
}
public void speakWithClient()
{
int recv;
byte[] data = new byte[1024];
IPEndPoint clientep = (IPEndPoint) newServerSocket.RemoteEndPoint;
Console.WriteLine("Connected with {0} at port {1}",
clientep.Address, clientep.Port);
string welcome = "Welcome to my test server";
data = Encoding.ASCII.GetBytes(welcome);
newServerSocket.Send(data, data.Length,SocketFlags.None);
Right here, it sends the given message back to the client, but it doesn't send the message to all threads.
while (true)
{
data = new byte[1024];
recv = newServerSocket.Receive(data);
if (recv == 0)
break;
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
newServerSocket.Send(data, recv, SocketFlags.None);
}
Console.WriteLine("Disconnected from {0}",
clientep.Address);
newServerSocket.Close();
}
}
class SimpleTcpSrvr
{
public static void Main()
{
int recv;
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any,9060);
Socket newsock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
newsock.Bind(ipep);
newsock.Listen(10);
Console.WriteLine("Waiting for a client...");
while (true)
{
Socket client = newsock.Accept();
NewClient threadliclient = new NewClient(client);
Thread newthread = new Thread(new ThreadStart(threadliclient.speakWithClient));
newthread.Start();
}
}
}
It's been a while since I've done any socket programming, but... don't you need to keep a list of your client sockets and loop through them every time you receive a message?
public static List<Socket> Clients = new List<Socket>();
while (true)
{
Socket client = newsock.Accept();
Clients.Add(client);
NewClient threadliclient = new NewClient(client);
Thread newthread = new Thread(new ThreadStart(threadliclient.speakWithClient));
newthread.Start();
}
public void speakWithClient()
{
int recv;
byte[] data = new byte[1024];
IPEndPoint clientep = (IPEndPoint) newServerSocket.RemoteEndPoint;
Console.WriteLine("Connected with {0} at port {1}", clientep.Address, clientep.Port);
string welcome = "Welcome to my test server";
data = Encoding.ASCII.GetBytes(welcome);
newServerSocket.Send(data, data.Length,SocketFlags.None);
while (true)
{
data = new byte[1024];
recv = newServerSocket.Receive(data);
if (recv == 0)
break;
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
foreach (Socket client in SimpleTcpSrvr.Clients)
{
client.Send(data, recv, SocketFlags.None);
}
}

Socket between C# server and C# client

I'm going to create a socket to send a string from console application server to AndroidWearable client. I use Visual Studio Xamarin, and I never use XML Language. When I click the button nothing happens, How can I improve my program?
Part MainActivity.cs
using Android.App;
using Android.OS;
using Android.Support.Wearable.Activity;
using Android.Views;
using Android.Widget;
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace AndroidClient
{
[Activity(Label = "#string/app_name", MainLauncher = true)]
public class MainActivity : WearableActivity
{
private TextView textView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
textView = FindViewById<TextView>(Resource.Id.text);
SetAmbientEnabled();
}
/** Called when the user touches the button */
// Incoming data from the client.
public static string data = null;
public static void StartListening()
{
// Data buffer for incoming data.
byte[] bytes = new Byte[1024];
// Establish the local endpoint for the socket.
// Dns.GetHostName returns the name of the
// host running the application.
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);
// Create a TCP/IP socket.
Socket listener = new Socket(ipAddress.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
// Bind the socket to the local endpoint and
// listen for incoming connections.
try
{
listener.Bind(localEndPoint);
listener.Listen(10);
// Start listening for connections.
while (true)
{
Console.WriteLine("Waiting for a connection...");
// Program is suspended while waiting for an incoming connection.
Socket handler = listener.Accept();
data = null;
// An incoming connection needs to be processed.
while (true)
{
int bytesRec = handler.Receive(bytes);
data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
if (data.IndexOf("<EOF>") > -1)
{
break;
}
}
// Show the data on the console.
Console.WriteLine("Text received : {0}", data);
// Echo the data back to the client.
byte[] msg = Encoding.ASCII.GetBytes(data);
handler.Send(msg);
handler.Shutdown(SocketShutdown.Both);
handler.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Console.WriteLine("\nPress ENTER to continue...");
Console.Read();
}
public void mainsendMessage(View view)
{
// Do something in response to button click
StartListening();
}
}
}
Part AXML-Origin
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage" />
Server C#
SERVER
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace Server_microsoft
{
public class SynchronousSocketListener
{
// Incoming data from the client.
public static string data = null;
public static void StartListening()
{
// Data buffer for incoming data.
byte[] bytes = new Byte[1024];
// Establish the local endpoint for the socket.
// Dns.GetHostName returns the name of the
// host running the application.
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);
// Create a TCP/IP socket.
Socket listener = new Socket(ipAddress.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
// Bind the socket to the local endpoint and
// listen for incoming connections.
try
{
listener.Bind(localEndPoint);
listener.Listen(10);
// Start listening for connections.
while (true)
{
Console.WriteLine("Waiting for a connection...");
// Program is suspended while waiting for an incoming connection.
Socket handler = listener.Accept();
data = null;
// An incoming connection needs to be processed.
while (true)
{
int bytesRec = handler.Receive(bytes);
data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
if (data.IndexOf(data) > -1)
{
break;
}
}
// Show the data on the console.
Console.WriteLine("Text received : {0}", data);
// Echo the data back to the client.
byte[] msg = Encoding.ASCII.GetBytes(data);
handler.Send(msg);
handler.Shutdown(SocketShutdown.Both);
handler.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Console.WriteLine("\nPress ENTER to continue...");
Console.Read();
}
public static int Main(String[] args)
{
StartListening();
return 0;
}
}
}
Thanks!
For example I have to inser some TextView o see the string? How can I make this or one button is necessary?

TCP Service & REST APIs

I have a GPS Tracker Device, I have run a TCP/IP Server Code which Successfully establishes connection with each device in a separate Thread and Device Keep sending its heart beat after one minute and server replies ON. When I send a command to get device location it gives me location and everything is working fine.
Now I want to get location from an android device using web service, Now I'm confuse how can I use running thread of a specific device from an Android App?
class Server
{
TcpListener server = null;
public Server(string ip, int port)
{
IPAddress localAddr = IPAddress.Parse(ip);
server = new TcpListener(localAddr, port);
server.Start();
StartListener();
}
public void StartListener()
{
try
{
while (true)
{
Console.WriteLine("Waiting for a connection... ");
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Connected!");
Thread t = new Thread(new ParameterizedThreadStart(HandleDeivce));
t.Start(client);
}
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}
}
public void HandleDeivce(Object obj)
{
TcpClient client = (TcpClient)obj;
NetworkStream stream = client.GetStream();
string data = null;
Byte[] bytes = new Byte[256];
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = Encoding.ASCII.GetString(bytes, 0, i);
Console.WriteLine("{1}: Received: {0}", data, Thread.CurrentThread.ManagedThreadId);
if (data.StartsWith("##"))
{
data = "LOAD";
}
else
{
data = "ON";
}
byte[] msg = Encoding.ASCII.GetBytes(data);
stream.Write(msg, 0, msg.Length);
Console.WriteLine("{1}: Sent: {0}", data, Thread.CurrentThread.ManagedThreadId);
}
client.Close();
}
}
Try making code look like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace ConsoleApplication16
{
class Program
{
const string IP = "123.456.789.000";
const int PORT_NUMBER = 1234;
static AutoResetEvent autoEvent = new AutoResetEvent(false);
static void Main(string[] args)
{
GPSClient client = new GPSClient(IP, PORT_NUMBER);
//start http client or equivalent here
while (true)
{
autoEvent.Reset();
autoEvent.WaitOne();
//wait for message from user/client on service port
string message = client.message;
//send message back to user/client
}
}
}
public class WebServer
{
}
public class GPSClient
{
const int BUFFER_SIZE = 256;
TcpClient client = null;
NetworkStream stream = null;
Byte[] bytes = new Byte[BUFFER_SIZE];
public string message { get; set; }
public GPSClient(string ip, int port)
{
try
{
Console.WriteLine("Connecting to Device... ");
client.Connect(ip, port);
Console.WriteLine("Connected!");
stream = client.GetStream();
stream.BeginRead(bytes, 0, BUFFER_SIZE, new AsyncCallback(HandleDeivce), stream);
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}
}
public void HandleDeivce(IAsyncResult ar)
{
NetworkStream stream = ar.AsyncState as NetworkStream;
string data = null;
int i = stream.Read(bytes, 0, BUFFER_SIZE);
data = Encoding.ASCII.GetString(bytes, 0, i);
Console.WriteLine("Received: {0}", data);
message = data;
if (data.StartsWith("##"))
{
data = "LOAD";
}
else
{
data = "ON";
}
byte[] msg = Encoding.ASCII.GetBytes(data);
stream.Write(msg, 0, msg.Length);
Console.WriteLine("Sent: {0}", data);
stream.BeginRead(bytes, 0, BUFFER_SIZE, new AsyncCallback(HandleDeivce), stream);
}
}
}

input string was not in correct format while working with sockets [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Hi I written simple client socket application, where client send some string to server, server receives it and convert the string to upper case and send back to client. Client print the message from server to console. But When I ran the application, I am getting 'input string was not in correct format' error while converting the bytes received from server. Since I am new to C# programming, Can some one help me to understand why this error coming, and how to resolve it?
Server.cs
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace Server
{
public class ServerSocket
{
private int port;
private Socket serverSocket;
public ServerSocket(int port)
{
this.port = port;
serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
/* Associates a Socket with a local endpoint. */
serverSocket.Bind(serverEndPoint);
/*Places a Socket in a listening state.
* The maximum length of the pending connections queue is 100
*/
serverSocket.Listen(100);
}
public void start()
{
Console.WriteLine("Starting the Server");
/* Accept Connection Requests */
Socket accepted = serverSocket.Accept();
/* Get the size of the send buffer of the Socket. */
int bufferSize = accepted.SendBufferSize;
byte[] buffer = new byte[bufferSize];
/* Receives data from a bound Socket into a receive buffer. It return the number of bytes received. */
int bytesRead = accepted.Receive(buffer);
byte[] formatted = new byte[bytesRead];
for (int i = 0; i < bytesRead; i++)
{
formatted[i] = buffer[i];
}
String receivedData = Encoding.UTF8.GetString(formatted);
Console.WriteLine("Received Data " + receivedData);
String response = receivedData.ToUpper();
byte[] resp = Encoding.UTF8.GetBytes(response);
accepted.Send(resp, 0, resp.Length, 0);
Console.WriteLine("Press some key to close");
Console.Read();
}
}
class Server
{
static void Main(string[] args)
{
ServerSocket server = new ServerSocket(1234);
server.start();
}
}
}
Client.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
namespace client
{
public class ClientSocket{
private Socket clientSocket;
private int port;
public ClientSocket(int port)
{
this.port = port;
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
public void start()
{
Console.WriteLine("Starting client socket");
try
{
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
clientSocket.Connect(serverEndPoint);
Console.WriteLine("Enter some data to send to server");
String data = Console.ReadLine();
byte[] bytes = Encoding.UTF8.GetBytes(data);
clientSocket.Send(bytes);
Console.WriteLine("Closing connection");
int receiveBufferSize = clientSocket.ReceiveBufferSize;
byte[] buffer = new byte[receiveBufferSize];
int receivedBytes = clientSocket.Receive(buffer);
byte[] receivedData = new byte[receivedBytes];
for(int i=0; i < receivedBytes; i++)
{
receivedData[i] = buffer[i];
Console.WriteLine(receivedData[i]);
}
String received = Encoding.UTF8.GetString(receivedData);
Console.WriteLine("Response : {}", received);
Console.WriteLine("Press Enter to close");
Console.Read();
clientSocket.Close();
}
catch (Exception e)
{
Console.WriteLine("Error while connectiong to server {}", e.Message );
}
}
}
class Client
{
static void Main(string[] args)
{
ClientSocket clientSocket = new ClientSocket(1234);
clientSocket.start();
}
}
}
The line:
Console.WriteLine("Response : {}", received);
should be:
Console.WriteLine("Response : {0}", received);

Why I can send data from TCP Client to Server, but not vice versa?

I wrote an asynchronous TCP server-client in C#. Both programs run successfully when I test them in one computer (server and client run simultaneously in the same machine). But when tested in two different computers, server-client connection is established and the client is able to send data to server, but the server seems to be not sending anything to its client.
By using TCPView, I know that both server and client is receiving/sending data as expected. I thought it was firewall blocking them, I've disabled it and no use. What's wrong with my code?
Server:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
// Server code
namespace ChatConsole
{
class Program
{
static Socket serverSocket, clientSocket;
static byte[] buffer;
const int defaultBufferSize = 1024;
static void Main(string[] args)
{
try
{
Console.WriteLine("This is server.");
// Create a new server socket.
serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Create IP End Point.
IPEndPoint ep = new IPEndPoint(IPAddress.Any, 1001);
// Bind endpoint to socket.
serverSocket.Bind(ep);
// Start listening for incoming client.
serverSocket.Listen(4);
// Execute callback method when client request connection.
serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), null);
while (true) { }
}
catch(Exception ex)
{
Console.WriteLine("from Main(): " + ex.Message);
}
}
private static void AcceptCallback(IAsyncResult ar)
{
try
{
// Store client socket handle.
clientSocket = serverSocket.EndAccept(ar);
Console.WriteLine("Client {0} joined.", clientSocket.RemoteEndPoint);
// Welcome the client when connection established.
buffer = Encoding.ASCII.GetBytes("Hello from server!");
clientSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(SendCallback), null);
// Begin receiving data from connected client.
buffer = new byte[1024];
clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), null);
}
catch (Exception ex)
{
Console.WriteLine("from AcceptCallback(): " + ex.Message);
}
}
private static void SendCallback(IAsyncResult ar)
{
// Terminate current send session.
clientSocket.EndSend(ar);
Console.WriteLine("Replied.");
}
private static void ReceiveCallback(IAsyncResult ar)
{
try
{
// Store the length of received data.
int received = clientSocket.EndReceive(ar);
if (received == 0)
return;
// Convert the received data to string then print in the console.
Array.Resize<byte>(ref buffer, received);
string text = Encoding.ASCII.GetString(buffer);
Console.WriteLine(text);
Array.Resize<byte>(ref buffer, defaultBufferSize);
// Send back message from the client.
byte[] data = Encoding.ASCII.GetBytes("from server: " + text);
clientSocket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), null);
clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), null);
}
catch (Exception ex)
{
Console.WriteLine("from ReceiveCallback(): " + ex.Message);
}
}
}
}
Client:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
// Client code
namespace ChatConsoleClient
{
class Program
{
static Socket clientSocket;
static IPEndPoint ep;
static byte[] buffer;
const int defaultBufferSize = 1024;
static void Main(string[] args)
{
try
{
Console.WriteLine("This is client.");
// Create new socket for client.
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Ask for server IP address.
string IP = Console.ReadLine();
// Create endpoint to be connected.
ep = new IPEndPoint(IPAddress.Parse(IP), 1001);
// Start connecting to the server.
clientSocket.BeginConnect(ep, new AsyncCallback(ConnectCallback), null);
buffer = new byte[1024];
clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), null);
while (true)
{
string text = Console.ReadLine();
byte[] data = Encoding.ASCII.GetBytes(text);
clientSocket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), null);
}
}
catch (Exception ex)
{
Console.WriteLine("from Main(): " + ex.Message);
}
}
private static void ReceiveCallback(IAsyncResult ar)
{
int received = clientSocket.EndReceive(ar);
if (received == 0)
return;
// Convert the received data to string then print in the console.
Array.Resize<byte>(ref buffer, received);
string text = Encoding.ASCII.GetString(buffer);
Console.WriteLine(text);
Array.Resize<byte>(ref buffer, defaultBufferSize);
clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), null);
}
private static void SendCallback(IAsyncResult ar)
{
clientSocket.EndSend(ar);
}
private static void ConnectCallback(IAsyncResult ar)
{
clientSocket.EndConnect(ar);
}
}
}
I have checked client and server running in two different systems but both of them having the same IP series and it works

Categories