Home > Net >  C # socket asynchronous communication problem at a time (super newbie question, beginner beginners)
C # socket asynchronous communication problem at a time (super newbie question, beginner beginners)

Time:01-14

 
using System;
Using System.Net;
Using System.Net.Sockets;
using System.Text;

The namespace server
{
Class Program
{
The static void Main (string [] args)
{
Console. WriteLine (" server: ");
The Socket server=new Socket (AddressFamily. InterNetwork, SocketType Stream, ProtocolType. Tcp);
IPEndPoint endpoint=new IPEndPoint (IPAddress. Any, 8625);
Server. The Bind (endpoint);
Server. Listen (10);
Server. BeginAccept (new AsyncCallback (Accpcallback), server).
Console.ReadLine();
}

Private static void Accpcallback IAsyncResult (ar)
{
The Socket server=(Socket) ar. AsyncState;
The Socket client=server. EndAccept (ar);
String remoteendpoint=client. Remoteendpoint. ToString ();
Console. WriteLine ($" have accepted the client {remoteendpoint} connection ");

//===assume that aaa was from client information
String triple="";
If (aaa=="123456")
{
Console. WriteLine (" database with this information ");
}
The else
{
Console. WriteLine (" the database without this message ");
}

Server. BeginAccept (new AsyncCallback (Accpcallback), server).
}
}
}


 
using System;
using System.Text;
Using System.Net.Sockets;

The namespace tcpclient
{
Class Program
{
The static void Main (string [] args)
{
Console. WriteLine (" client ");
Socket client=new Socket (AddressFamily. InterNetwork, SocketType Stream, ProtocolType. Tcp);
Try
{
Client. The Connect (" 192.168.88.223 ", 8625);
String remoteendpoint=client. Remoteendpoint. ToString ();
Console. WriteLine ($" successfully connect to the server to {remoteendpoint} ");

//===to send a message to the server
String triple="123456";

}
The catch (SocketException ex)
{
Console. WriteLine (ex. Message);
}
}
}
}


Two side code above is C/S, I want to process is as follows: (1) is the validation service)
Client connection, sending a data to the server, the server do the corresponding processing again after receiving feedback to the client,

After I watched a lot of code in the baidu, into how to modify all bad, for bosses, give a the most simple, thanks to bosses, bosses make a fortune in 2021! Walk good luck!

CodePudding user response:

Eldest brother, you this baidu is false, baidu on a lot of socket, you is how to mix the 13 years of membership

CodePudding user response:


Ashamed to say that, I'm not a regular, are self-taught, bit by bit and my job is not programming, intermittent, and hobbies

CodePudding user response:

Both sides didn't write code, BebinRecieve, where go to?
  •  Tags:  
  • C#
  • Related