通信


前述のサーバーソケットクライアントソケットを使って通信テストを行います。

		
public partial class FormSocket : Form
{
	public FormSocket()
	{
		InitializeComponent();
	}

	SocketClient _client;
	SocketServer _server;

	private void FormSocket_Load( object sender, EventArgs e )
	{
		// サーバーが9987番ポートで接続待ち
		_server = new SocketServer();
		_server.Listen( 9987 );

		// クライアントがローカルPCの9987番ポートへ接続要求
		_client = new SocketClient();
		_client.Connect( "127.0.0.1", 9987 );
	}

	private void button1_Click( object sender, EventArgs e )
	{
		// クライアントからもサーバーからもデータ送信できる
		_client.Send( new byte[ 3 ] { 1, 2, 3 } );
	}
}
		
	


inserted by FC2 system