When working with TCP client sockets I often find myself frustrated with the lack of event-driven support. I usually end up writing a whole bunch of code to determine disconnects, reconnecting, etc and I figuired it's time to just write my own class for this stuff. I figuired I'd share it with all of you. The implementation is quite simple, I'll provide an example below. I have XML commented all the public properties and methods, the rest is up to you to figuire out if you want to make any changes! public partial class Form1 : Form { EventDrivenTCPClient client; …

Member Avatar
Member Avatar
+5 forum 16

Hello, on Hotmail/Outlook webmail, when I receive an email message in the spam folder (formally Junk), I can mark the message as **Not Junk**. The server will then start to deliver the messages from that source, directly into the Inbox, working like a whitelist. Is it possible to do the same through the IMAP commands? I have been testing for a while, but I haven't find a solution. Moving the messages from Junk to Inbox does not solve, because the following messages will end again in the Junk folder. At this point [this seems appropriate.](https://youtu.be/o1tj2zJ2Wvg) I have tried to display …

Member Avatar
Member Avatar
+0 forum 1

Hi Dw. I have a MySql server database, and I'm polling data from the database. The problem I'm getting is that when I'm retrieving users activities I only get the first record only which is on `Row(0)` or the first record with that username. Suppose I have a database like this: `------------------------------------------------- |Activity | ActUser |Username | ------------------------------------------------- |working |John |Steve | -------------------------------------------------- |done |thabo |tomas | ------------------------------------------------- |confirmed|amanda |Steve | -------------------------------------------------` Now the problem is retrieving all records with username `(Steve)`. In the above example it should be 2 records retrieved one with John and another with amanda. This …

Member Avatar
Member Avatar
+0 forum 4

I'm writing a simple server allowing me and my friends to send information to each other. Currently I've got the client down easy enough, it's all set up and I can communicate with servers. The problem is I can't get the server to work for some reason, I use working examples offline and it just refuses to function. Here's the code: import socket HOST = '' PORT = 8888 SLOTS = 10 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.bind((HOST, PORT)) except: print "Failure To BInd" s.listen(SLOTS) conn, addr = s.accept() I get an error saying that in the s.listen(SLOTS) line, an …

Member Avatar
Member Avatar
+0 forum 3

Dear all I am trying to send request to client device in Hex format and receive data into decimal format. By seeing forum and tutorial class. I could able to send and receive data from client device.Now I wanted to check the data i received valid or not. In order to test it i wanted to convert the data from hex to dec. I am also confused How client data being received here. My code: import socket TCP_IP = '192.168.1.3' TCP_PORT = 8899 BUFFER_SIZE = 1000 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) s.send('01030000001d85c3'.decode('hex')) Decode_hex='01030000001d85c3'.decode('hex') print Decode_hex print "decode hex:",Decode_hex data …

Member Avatar
Member Avatar
+0 forum 4

Hey everyone, I'm looking for some help with coming up with a system to communicate data between client and server sockets. I was thinking of a command system, but that would only work when the client is sending a request to the server, not when the server is returning data from a request. How would you accomplish this? Thanks!

Member Avatar
Member Avatar
+0 forum 4

Hi Dw. I am developing a client server multi-thread application. This application uses signals(certain messages as signals), in order to perform a task for a client. For instance if a client wants to login, the client send a message as: `Login:<username>:<password>` and on a server I first check if the message contains `:` and if it does then I split the message using `:` as a split. I am using the client server code from http://www.vb.net-informations.com/communications/vb.net_multithreaded_server_socket_programming.htm But I didn't use it as Console its both WinForms. I'm facing avery hug problem here. All of my activity codes are under the …

Member Avatar
Member Avatar
+0 forum 12

I have done a socket programming using bonecp as the database pooling for mysql. Suddenly I notice a lot of socket connection made but then after a few hours I got too many open files. I have set the timeout but somehow it did not timeout I don't know why. Why did the timeout did not trigger or worked in this scenario? I need to know is this due to database pooling or socket problem? Below is snippet of my code. In my code I notice in the logs the connection is made and stops at this line- System.out.println("\n\n Trying …

Member Avatar
Member Avatar
+0 forum 2

xml file <?xml version="1.0" encoding="UTF-8" standalone="no"?><movies> <movie id="1111"> <title>Blackhat</title> <genre>thriller</genre> <duration> 90 mins </duration> <age>28</age></movie> <movie id="1002"> <title>The Wedding Ringer</title> <genre>comedy</genre> <duration> 100 mins </duration> </movie> <movie id="1003"> <title>The Avengers</title> <genre>action</genre> <duration> 180 mins </duration> </movie> <movie id="1004"> <title>Taken 3</title> <genre>action</genre> <duration> 100 mins </duration> </movie> <movie id="1005"> <title>Insurgent</title> <genre>Science Fiction</genre> <duration>180 mins</duration> </movie> <movie id="1006"> <title>Jurassic World</title> <genre>Adventure</genre> <duration>120 mins</duration> </movie> <movie id="1111"> <title>Interstellar</title> <genre>Science Fiction</genre> <duration>180 mins</duration> </movie> </movies> what i want to adding movie id tag to the last line, for example <?xml version="1.0" encoding="UTF-8" standalone="no"?><movies> <movie id="1111"> <title>Blackhat</title> <genre>thriller</genre> <duration> 90 mins </duration> <age>28</age></movie> <movie id="1002"> …

Member Avatar
Member Avatar
+0 forum 1

try { File file = new File("/Users/Alex Ting/Desktop/test2/MovieList.xml"); DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = dBuilder.parse(file); NodeList movielist = doc.getElementsByTagName("movie"); for(int i =0;i<movielist.getLength(); i++){ Node m=movielist.item(i); if(m.getNodeType()==Node.ELEMENT_NODE){ Element movie = (Element) m; String movieID = movie.getAttribute("id"); NodeList mnamelist=movie.getChildNodes(); for(int j=0;j<movielist.getLength(); j++){ Node n = mnamelist.item(j); if(n.getNodeType()==Node.ELEMENT_NODE){ Element name = (Element) n; //System.out.println("Movie ID: "+ movieID +"\n"+ name.getTagName()+ ": "+ name.getTextContent()); //System.out.println(name.getTagName()+ ": "+ name.getTextContent()); if(name.getTextContent().equals(smoviename)){ System.out.println("Movie Id :"+movie.getAttribute("id")); System.out.println(name.getTagName()+ ": "+ name.getTextContent()); } } } } } } catch (Exception e) { e.printStackTrace(); } my xml file <?xml version="1.0" encoding="UTF-8" standalone="no"?> <movies> <movie id="1001"> <title>Blackhat</title> <genre>thriller</genre> <duration> 90 mins </duration> …

Member Avatar
Member Avatar
+0 forum 1

I want to pass the string from client to server and the server will display the string. First the client enter the option 1 and the server will reply ask from the movie name. My problem is i cannot enter the name from client and send it to server and display the name. Here is my code for server and client TCPServer import java.io.*; import java.net.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; class TCPServer { public static void main(String argv[]) throws Exception{ String clientSentence; String capitalizedSentence; String smoviename; ServerSocket welcomeSocket = new ServerSocket(6789); System.out.println("Waiting …

Member Avatar
Member Avatar
+0 forum 2

Hi, so I've got this multithreaded server which correctly waits for clients and assigns them to a worker thread. From there, the client is sent an object `Packet` which contains variables `Player` and `Round` (simplified, it contains more data but these are the most important). I'm building a simple top trumps game and I need two enable two players to play it via LAN. My idea is to send a `Packet` object back and forth. The apps would populate the GUI based on the packet's contents. Threads decide weather to send or receive based on `Round`: This is being run …

Member Avatar
Member Avatar
+0 forum 8

I am Developing an Client Server socket application .Am reading Strings in server side for multiple clients inside run(override) method and I getting EOF Exception at readUTF. I Dont know why the error is comming and how to rectify it. while (ss.compareTo("true") == 0) { System.out.println("Waiting for port " + port); sdc = soc.accept(); cs[i] = sdc; System.out.println("Connected port " + cs[i]); DataInputStream dind = new DataInputStream(cs[i].getInputStream()); DataOutputStream dout = new DataOutputStream(cs[i].getOutputStream()); String password = dind.readUTF(); String dept = dind.readUTF(); uniqueName = dind.readUTF(); String username = dind.readUTF(); String ipaddress = dind.readUTF(); String macaddress = dind.readUTF(); String groupname = dind.readUTF(); }

Member Avatar
Member Avatar
+0 forum 3

Now am working with java application . I have to connect server and client through No-Ip Duc host.Is it possible or not??? Server side code: ServerSocket ss=new ServerSocket(5223); System.out.println("Waiting for client"); Socket soc=ss.accept(); System.out.println("Connected"); client side code: Socket soc=new Socket("rmcsnoiptest.ddns.net", 5223); This is what i tried.

Member Avatar
Member Avatar
+0 forum 1

I have this code. Its not the entire code because its a Blender addon with many lines that are unrelated to sockets so I give here only the part that deals with the sockets which I kept isolated from the rest of the program. def create_thread(): global threadSocket,listening threadSocket = threading.Thread(name='threadSocket', target= socket_listen) listening = True create_socket_connection() threadSocket.start() def socket_listen(): global receivedSocket,listening, receivedData,socketServer, socketMessages, pherror socketServer.listen(5) while listening: (receivedSocket , adreess) = socketServer.accept() receivedData = (receivedSocket.recv(1024)).decode("utf-8")[:-2] socketMessages.append(receivedData) receivedSocket.sendall('Hello from Blender!\n') receivedSocket.close() def create_socket_connection(): global socketServer socketServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socketServer.bind(('127.0.0.1',4000)) If you want to see the entire code, it can …

Member Avatar
Member Avatar
+0 forum 1

Hello, I have two applications; a server and a client which use simple TCP Sockets to connect to each other and send the data. The only problem I have is that I am struggling to associate usernames with the accepted sockets on the server. The server is able to accept and hold multiple socket connections in order for multi-user chat and I have set up a simple string list ready for the usernames but since I am unable to find any socket IDs or such-like, I can't find a way to associate a name with a socket. I have looked …

Member Avatar
Member Avatar
+0 forum 3

Hello guys..!! I'm new to python and I have a task which require me to write a simple TCP server which will interact with the web browser. I have done some coding as well as researching over the internet to find relevant notes and materials but none helped. What I want to do is that I would run a TCP server which will open a socket and listen on some particula port e.g. 12000. Then configure the browser to connect on that port number and try to send a GET request. For example if I type http://localhost:12000/www.google.com the server should …

Member Avatar
Member Avatar
+0 forum 3

Here is my code. #include <iostream> #include <math.h> #include <winsock.h> #include <windows.h> #include<stdio.h> #include<stdlib.h> #include<string.h> using namespace std; int main() { SOCKET s; WSADATA wsadata; int error = WSAStartup(0x0202, &wsadata); //Did something happen? if (error) return false; //Did we get the right Winsock version? if (wsadata.wVersion != 0x0202) { WSACleanup(); //Clean up Winsock return false; } //Fill out the information needed to initialize a socket… SOCKADDR_IN target; //Socket address information target.sin_family = AF_INET; // address family Internet target.sin_port = htons (53000); //Port to connect on target.sin_addr.s_addr = inet_addr ("192.168.29.1"); //Target IP s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); //Create socket if …

Member Avatar
Member Avatar
+0 forum 2

I am using following gdiscreen() function which takes screenshot jpg image into buffer.I am sending this buffered image using sento() over UDP.I am unable to convert this char array data sent back into image .I appreciate any help you can provide void gdiscreen() { char buffer[61400]; using namespace Gdiplus; wchar_t filename[200]; memset(filename,0,sizeof(filename)); cnt++; GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); EncoderParameters encoderParameters; ULONG quality; { HDC scrdc, memdc; HBITMAP membit; scrdc = ::GetDC(0); int Height = GetSystemMetrics(SM_CYSCREEN); int Width = GetSystemMetrics(SM_CXSCREEN); memdc = CreateCompatibleDC(scrdc); membit = CreateCompatibleBitmap(scrdc, Width, Height); HBITMAP hOldBitmap =(HBITMAP) SelectObject(memdc, membit); BitBlt(memdc, 0, 0, Width, Height, scrdc, …

Member Avatar
Member Avatar
+0 forum 1

I am new to socket programming.I am trying to send datagrams containing image data(jpg) from one host to another continuously.I want to use C++.I have not came across detailed steps on how to achieve this for images anywhere.can somebody explain or link me to such tutorials?

Member Avatar
Member Avatar
+0 forum 3

Hello, I am currently trying to use boost asio for IPC. I ran into 2 strange issues: 1) when using the acceptor class, when I bring my process up, I get the error 'Already open' when trying to listen. The port I am trying to bind to is definitely not being used by another process. This only happens for a couple of my processes (others work fine). 2) when trying to establish a connection to a server (one that works fine from above), both processes receive the connection (and also disconnection when I kill one), but when I try to …

Member Avatar
Member Avatar
+0 forum 3

import java.io.*; import java.net.*; import java.util.*; public class UselessHTTPServer04 { public static void main(String args[]) throws Exception { int port = Integer.parseInt(args[0]); ServerSocket serverSock=new ServerSocket(port); while(true) { Socket conn = serverSock.accept(); Scanner scanin = new Scanner(conn.getInputStream()); String line=null; int nlines=0; while (true) { line = scanin.nextLine(); if(line.length()==0) break; nlines = nlines + 1; System.out.println("line "+nlines+": "+line); } String reply="HTTP/1.0 404 Not Found\r\n" + "Connection: close\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "<h1>Sorry, work in progress</h1>\r\n"; OutputStream outs = conn.getOutputStream(); outs.write(reply.getBytes()); conn.close(); } } } How do you add code after the for loop that prints the lines but before the …

Member Avatar
Member Avatar
+0 forum 2

Similar to echoserver, but this one handles multiple clients by forking the process.

Member Avatar
+0 forum 0

i have a simple note and images storing java program that stores data into the server..i'm confused about what to use for building the server..should the server be built using sockets?? or which listens for http requests (the client sends json data)?? could anyone please tell me which one would be better?? how would you make this type of server? thank you/

Member Avatar
Member Avatar
+1 forum 5

This is a simple echo server that I've written while learning sockets programming. Compile the server and run it. You can connect to it using telnet like this: telnet localhost 1337 Disconnect the client by typing "/quit" without quotes.

Member Avatar
+0 forum 0

I am new to socket programming and I am trying to establish a connection between my client and server and if it's successful the user can 1) -Input message, the message will be send to the server -the server will send a "I got your msg" back to the client. -The user can input as many messages as he/she wants until he/she has enter "Q" to go back to the main menu. 2)exit from program. the problem I faced was 1)At 1.Input Message Client side - the server only reads the first message from the client input, after that it …

Member Avatar
Member Avatar
+0 forum 2

I am making a programe based on socket programing in which client can download one of the listed books from server. I have come up with this code but the problems with it are: 1) It doesnt downloads pdf file greater than 1MB. 2) It allows client to download 1 file only and then the connection is closed. I want the client to be able to download as many files as he/she wants. Please suggest improvements. ***CLIENT CODE:*** int filesize=10223860; int bytesRead; int currentTot = 0; Socket socket = new Socket("127.0.0.1",15123); BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DataOutputStream outToServer = …

Member Avatar
Member Avatar
+0 forum 3

I'm trying to send data back and forth between two computers using a Socket (TCP). The data is in the form of serialized Packet objects. At an early point in the application, it must send 25 or so Packets of the same type to the other side. See Case 1 in HandlePacket(). After a few Packets of this type are sent (2 to 5, it's random), the other side crashes with a SerializationException: "Binary stream '0' does not contain a valid BinaryHeader." I've confirmed that I am always reading the same amount of data from the socket that was sent …

Member Avatar
Member Avatar
+0 forum 13

Please, I am trying to build a chat program in python i have built a chat client program and a server program, I want to ask someone told me that I don't need to build a server all i need to do is connect a db server directly and the second client continually reads just a row to save bandwidth for any new messages is this possible? ... if ye .. what are the up's and down's?

Member Avatar
+0 forum 0

Hello! I would like some help with a piece of java code that i'm having problem. I have to make simultaneous tcp socket connections every x seconds to multiple machines, in order to get something like a status update packet. I use a Callable thread class, which creates a future task that connects to each machine, sends a query packet, and receives a reply which is returned to the main thread that creates all the callable objects. My socket connection class is : public class ClientConnect implements Callable<String> { Connection con = null; Statement st = null; ResultSet rs = …

Member Avatar
Member Avatar
+0 forum 8

The End.