tcpclient

Using events on multithreading socket server

本小妞迷上赌 提交于 2019-12-25 11:56:36
问题 Im making a server for a new game proyect and im using C# (.NET Framework v4.5) for both client and server. Im currently using something like this to manage my players. new Thread(() => { connection.ListenAndSend(); }).Start(); public void ListenAndSend() { while(working) { if(someThingToRead) { //Listening logic here //Here i call my event for dataReceived with the data i just read. } else if (queue.Count > 0) { Send(queue.Dequeue().Data); //Send data from the Queue } } The use of a Queue is

Lapsnaper TCP connection specification

心不动则不痛 提交于 2019-12-25 08:58:33
问题 I am using Lapsnapper (a transponder timing system) running on Android. Lapsnapper enables a TCP/IP server with which a connection can be made, to build a custom interface and get some other relevant data RE: the transponders etc from the system. I do not understand the Lapsnapper tcp server specification. I have done some tcp stuff before, but I am mostly a higher level programmer and to be honest I am a bit out of my depth with this raw TCP stuff. The spec reads: What I don't understand is

binding a client to a local port

旧巷老猫 提交于 2019-12-25 04:17:27
问题 I am trying to configure my TCP client to use a specific local port to connect to another TCP server. I am using the code below but it doesnt' work. Do you know what I am doing wrong and if this is possible? I am using LINUX machine. Thanks AFG int localport=32000; m_clientfd = socket( AF_INET, SOCK_STREAM, 0 ); assert( m_clientfd >= 0 ); // someone set the localport struct sockaddr_in sa_loc; struct hostent* pLocalHostInfo = gethostbyname( "localhost" ); long LocalHostAddress; memcpy(

Conect Java client with Python server

妖精的绣舞 提交于 2019-12-25 02:57:22
问题 I made a server python with the next code (i think the rest of the code isn't necessary): while 1: data = conn.recv(BUFFER_SIZE) if not data: break print "received data:", data conn.send(data+'\r\n') conn.close() and when i try to received the echo with a Java client, i get a strange message when printing on console: Mensaje recibido = java.io.DataInputStream@1cf2a0ef At server point, I'm receiving good the message: Hola Mundo. The code in Java is: DataInputStream ims; String data; s = new

Receive messages from gmail

假装没事ソ 提交于 2019-12-25 02:19:27
问题 I try to receive messages from gmail account but get an error: host not found . Here is my code: using (TcpClient client = new TcpClient("pop.gmail.com ", 995)) using (NetworkStream n = client.GetStream()) { ReadLine(n); // Read the welcome message. SendCommand(n, "my_login@gmail.com"); SendCommand(n, "my_password"); SendCommand(n, "LIST"); // Retrieve message IDs List<int> messageIDs = new List<int>(); while (true) { string line = ReadLine(n); // e.g. "1 1876" if (line == ".") break;

TCPClient not reading the incoming data

折月煮酒 提交于 2019-12-25 00:43:18
问题 I am working on a C# Application which connects to the host over TCP/IP to send and then receive the response using TCPClient Stream. The Problem is I can send data using the Stream.Write(...) but when I try to get the response against my sent data by calling Stream.Read(...), it hangs and never returns. I've checked the Network sniffing tool like Wire-Shark and can see that the data from the host is being received by my network interface. Why this data is not getting read by my TCPClient?

How to make TCP client which send request and receive response .Also accepts the messages pushed from server

为君一笑 提交于 2019-12-25 00:13:35
问题 I have to create a tcp client 1)-which will send request msg to server and receive response for it 2)- Some time the server push msg to the client without any request from clientSo client should accept and read it . So I have already asked the question for the 1 part of it My tcp client using spring integration not able to get response and tried to reach some solution .But for second part i am confused what to use tcpoutbound gateway or inboundgateway with client flag enable. Kindly suggest

TCP/IP detect if there is a currently connected client on a listener

左心房为你撑大大i 提交于 2019-12-24 14:04:52
问题 Is there any way for my TCP/IP listener to detect if there are currently conencted client? This is my code: Public Sub StopListen() client.Close() tcpClientThread.Abort() server.Stop() SyncLock accessLock endThread = True End SyncLock Btn_Listen.Text = "Listen" End Sub The problem in that code is whenever the user pressed the Stop Listen button and there are currently no cients connected to my listener an error occurs. How can I do something like this? Public Sub StopListen() If

Visual Basic form freezes after receiving tcp/ip response

喜你入骨 提交于 2019-12-24 12:06:11
问题 I have a basic TCP/IP communication setup between Python on a Linux host and Visual Basic on a windows host. The windows host seems to work fine, as a test, I send a 0 to the Linux machine and have it respond with a 0 printed into the Visual Basic debug console. All works fine but after Visual Basic receives the response and display it successfully, it freezes the form so I can't press another button. Here's an example of the code. Imports System.Net Imports System.Net.Sockets Imports System

Is it possible to detect if a socket is in the CLOSE_WAIT state?

情到浓时终转凉″ 提交于 2019-12-24 10:32:00
问题 I am using a TcpClient object to send and receive data. When a client loses its connection, I can see by using TcpView that its associated connection is in a CLOSE_WAIT state. Is it possible in c# to see the state of a socket? I simply want to detect the CLOSE_WAIT state so I can close the socket on the server end. I understand that I can wait to receive bytes for a certain amount of time and then close the connection if nothing is received. I just would rather close the socket and its thread