Click here to Skip to main content
15,891,253 members
Everything / Sockets

Sockets

sockets

Great Reads

by ObiWan_MCC
A C# SMTP server (receiver).
by Florian Rappl
Creating a highly extensible presentation app with multi-user and device integration for tablets.
by _m0n
Connect to PC with no public IP using Node.js app for reverse port forwarding / tunneling
by tonywilk
Example server and client using different protocols over a Websocket (php/js)

Latest Articles

by honey the codewitch
Explore adapting Socket's async model to a task based one and adding some awaitable socket operations to your projects
by Greg Utas
Replacing its erase() function
by Mircea Neacsu
C++ streams for socket communications in Windows
by pdoxtader
A multithreaded server class that accepts multiple connections from a provided client class. Each client can send and receive files and text (byte data) simultaneously along 250 available channels.

All Articles

Sort by Updated

Sockets 

N 30 Apr 2024 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
U 30 Apr 2024 by Ezma
How to make our sender-server-receiver Java code into a client-server mail exchange code that does the follwoing: Each client can send and receive simultaneously (i.e. multi-threading): using multithreading, each client should act as a receiver...
16 Mar 2024 by Line Item
I would try running this from a command line, with some adjustments for that to make it a simple command. Get that to work then add to that a little at a time. Maybe then try moving that to PowerShell. Get that to work then add more until you...
8 Feb 2024 by KarstenK
At first: Log all your close() calls. I guess there is one you do not want to be executed. But common speaken: You need to debug it. Because you wrote that it is some timing problem, you need to add timestamps in your debugs log. The disconnect...
8 Feb 2024 by mathiv327
Hi, Am trying relevent with socket programming but my thing is long duration connection which is deciated connection. but every after 1 min connection resetting connection due to recv failure with is error no : 22 error message : invalid...
12 Nov 2023 by headshot9x
I have a WinForms application C#. In here, I used TcpClient/Socket and NetworkStream. I have created multiple thread to handle sending/receiving from client/server. Assuming I'm forced to use TcpClient/Socket, I won't use other libraries or...
10 Aug 2023 by pavan idirect
I am trying to come up with a design to efficiently send a tree data structure (each node can have more than 2 branches) to a socket/different process etc. There seems to be a cap on how much data can be sent in one message (1500 Bytes). The tree...
2 Aug 2023 by headshot9x
Hi, I have a connection to the server, I get data info from the server. Everything working fine if the server sends small data, a few hundred bytes, the problem occurs when the server sends large data, about a few thousands bytes, then I only...
2 Aug 2023 by Andre Oosthuizen
The problem you are facing is likely related to the way you are handling the data reception. Reading data from the stream using 'stream.Read' may not guarantee that you receive all the data at once, you should modify your code to read from the...
2 Aug 2023 by OriginalGriff
For starters, get rid of the goto crap, and learn about if ... else if ... else can do to make your code readable. You should also look at a using block to ensure the server socket connection is released ... THen use the debugger to find out...
17 Jul 2023 by Mohammad sajjadi
07/17 13:07:29: Launching 'app' on Pixel 6 Pro API 33. Install successfully finished in 1 s 677 ms. $ adb shell am start -n "com.example.soccergamedevelopmentproject/com.example.soccergamedevelopmentproject.MainActivity" -a...
16 Jul 2023 by Mohammad sajjadi
I'm trying to set a connection between 2 devices. As a matter of fact, I'm writing a game application, and I want to run it in 2 devices. One of these devices is a virtual device, and the other one is my phone number, a physical device. I need to...
12 May 2023 by Member 10601191
As you've mentioned '...the shell...' , I presume you're on a linux/unix platform. Why not pipe the output to a file using the tee command? This means you Won't need to change your existing code if its already sending output to stdout. ...
8 May 2023 by Member 15992924
/* Function: do_server() - write data to stdout */ void do_server(int fd) { char buf[BUFS]; int r; int read_bytes(int, char *, int); while((r = read_bytes(fd, buf, 1)) > 0) write(1, buf, r); } How can I make here that...
2 May 2023 by merano99
If you really mean concurrent in the sense of parallel, this would be possible with threads. Since the buffer is then a critical resource, it is necessary to synchronize here. Rick's suggestion to first fill the array buf[] until buf[] is full...
1 May 2023 by Rick York
What you have reads one byte at a time and writes it to file descriptor 1. You need to assemble a line of text in another buffer and then call write_line with it. The code you have will probably work OK for output but you might have to add...
1 May 2023 by Member 15992924
hello: I am trying to create a socket server that is working correctly for me. I just have a problem. I try to write what I receive from the data in the socket in a file but it is not writing it to me. The other extreme point sends me the data...
30 Jan 2023 by Member 14623639
I have a client which connects to server with 3 connections and server is receiving all the data from these connections but after some processing in the client side server detects that these 3 connections are disconnected. I tried executing the...
9 Jan 2023 by Member 14623639
I have a program with server and client both on different machines. What the program do is send continuous images to server from client. Here client send the datasize first and then the data and similarly server receives the data size in byte[4]...
9 Jan 2023 by pdoxtader
I'm very late to the party here, and this is probably already resolved. Griff and Dave gave some good advise - but here are some thoughts anyway; 1.) You're running the client and server on separate machines? Don't do that yet. You're just...
31 Dec 2022 by Member 11469340
My recommendation is to send/receive the "image data" in chunks instead of trying to push all the data at once into the socket. Use a MemoryStream to write the accumulated data.
29 Dec 2022 by OriginalGriff
Start by not swallowing your exceptions: replace catch { } with something to log the problem. All you do at the moment is say "if it does something wrong, I don't care, ignore it" which means that the data you are sending could be complete...
2 Nov 2022 by OriginalGriff
Repost: Deleted. Please do not repost your question; use the Improve question widget to add information or reformat it, but posting it repeatedly just duplicates work, wastes time, and annoys people. I'll delete this one.
12 Oct 2022 by User 14130253
(Why Reply Button Not Work? I Have Edit Question and add New Information Every Time Some One Comment)First of All Sorry for my Bad English. I Don't Know a Lot English so Hope Every One Can Understand What I Mean. Why BeginSend Have High CPU...
26 Sep 2022 by Death Smoke
I'm trying to make a connection between two computers both of them are using tp-link adapter , but i'm not receving anything from client . #include #include using namespace std; int main() { ...
14 Sep 2022 by Death Smoke
The Code dont print the Blankspace when I type it between words in the message getline it only print first word or last letter but if i write between words any character like -./\_ it will print the full message , Example : -Without character: I...
14 Sep 2022 by Rick York
jeron1 gave you the answer. Here are a couple of references you should consult to verify what was stated : operator>> (string) - C++ Reference[^], this one describes the redirection operator and this one : istream::getline - C++ Reference[^]...
4 Aug 2022 by crypL edEntity
I am trying to send an image via python sockets. I wrote a simple script for doing it. server.py import socket import cv2 import sys c = 0 q1 = '127.0.0.1' q2 = 10001 s = socket.socket() s.bind((q1, q2)) s.listen(5) image_path = sys.argv[1]...
4 Aug 2022 by Richard MacCutchan
Using a for loop: for i in fh: c.send(i) Is the wrong way to do it. A binary file has no concept of 'lines' or records, so Python will read it one byte at a time. You should use the read(size) function to read blocks of data until all the...
10 Jul 2022 by Member 15078716
Ping to a known location that you are confident is reachable. If the return indicates that the location is unavailable, then ping somewhere else. Do this a few times, once to each location, and if multiple locations are unavailable, then you...
16 Jun 2022 by Member 14915174
Hello, this is my first question on this website, hope I do good :) so I'm new to c++ and started working on a project because I like to learn by doing, the project is made of two applications one client and one server and they communicate using...
2 May 2022 by LF FF
I want to be able to use a single socket if possible to subscribe to multiple events of the same type (but with different parameters) over the socket of the same type, in order to keep track of various data streams over the same socket if at all...
2 May 2022 by Greg Utas
I don't know what you mean by "events" and "parameters" in your question. But you mentioned data streams, so I assume you're using TCP, or something that runs on top of TCP. A TCP socket usually communicates with one peer, from which it receives...
29 Mar 2022 by jake_jane
It sends actually all bytes and files successfully. The problem is when it is received on the server-side. It receives the whole data byte but It is not receiving the whole packet data. Help me, please Here is my code. What I have tried: Sender...
29 Mar 2022 by Greg Utas
If you're writing code at this level, you need to debug it yourself. It's very unlikely that anyone here will do it for you. Even if they wanted to, they'd first have to create the parts of your code that are missing, like socket allocation. If...
21 Mar 2022 by mathi1234
Hi, Actually my scenario is this socket connection is dedicated. i have to check the connection before for every string sending, is that below statement can be able check the connection as my case or not? if(0 != getsockopt(l_ClientSocket,...
6 Mar 2022 by Ayesha Tassaduq
i am trying to send a data frame through socket. But I got some errors i try to remove them but can't. can anoyone help me What I have tried: i have tried this code import socket import pandas as pd import pickle df =...
6 Mar 2022 by Richard MacCutchan
Look at the documentation: pickle — Python object serialization — Python 3.10.2 documentation[^]. The load method requires a file object as the first parameter.
26 Jan 2022 by M Imran Ansari
Check the following link for connectivity: Database Connectivity using C/C++ - GeeksforGeeks[^]
21 Jan 2022 by Member 13489621
Hi, I am developing a multi-client/single-server project that communicates through sockets. Server Go: The main program listens to a new connection, when a client connects to the server it's handled by a goroutine. On the goroutine I have a...
21 Jan 2022 by Greg Utas
A serious server will be implemented with synchronous (blocking) sockets. Each socket has a thread that waits for stuff to arrive on its socket. All this thread does is put messages on a work queue that an application thread will service. The...
20 Jan 2022 by RickZeeland
You can find an example here: Asynchronous Client Socket Example - .NET Framework | Microsoft Docs[^] If you have a lot of traffic you also might consider queueing.
22 Aug 2021 by Member 15328761
Hello. I want to create a Java server that will allow 2 or more sockets to communicate with each other. I tried this with the code shown below and the second client to connect can send to the first one, but the first to connect cannot send to the...
22 Aug 2021 by Edgr78
I need to get the HTML from a website so that I can parse it and use regex to detect patterns, such as links ("href"). Is it even worth Parsing? What I have tried: I have attempted to use https://docs.python.org/3/library/socket.html to get the...
22 Aug 2021 by Afzaal Ahmad Zeeshan
I already gave you the answer to this question on https://www.codeproject.com/Answers/5310985/How-do-I-make-a-HTML-parser-from-scratch-Python#answer1[^]. Do not repost the question as the answer to your problem remains the same.
21 Aug 2021 by OriginalGriff
You can do it but ... you'd be better off using a HTML scraping package such as Beautiful Soup: Build a Web Scraper With Python – Real Python[^] which will do most of the "donkey work" for you.
18 Aug 2021 by Member 8677306
I'm working on a C# winforms application that would simulate n-number of client socket connections to an asynchronous socket server. The form would have a NumericUpDown control where the user could select from 1 to 20 clients. And when executed...
18 Aug 2021 by OriginalGriff
Just create a loop, and inside the loop create a separate thread or task for each client. In the thread code, create the socket, connect it, and do whatever you have to with it. This is probably a good starting place as it allows progress...
16 Aug 2021 by Member 8677306
I'm writing an application in C# where I need to communicate with appx 15 TCP/IP based barcode scanners. The scanners are set up as servers. I need a client that will listen and receive data from the servers as barcodes are scanned. There will...
16 Aug 2021 by Greg Utas
I agree with Richard's suggestion. What you're calling a client is, in effect, a server, because it is presumably providing a service, such as updating a database. Even if it sends no application-level response to the scanners, the fact that TCP...
4 Aug 2021 by Mohammed Khalifa 2021
I have done socket programming in python for my TCP based device now I want to send data to mqtt broker from this socket program so I tried to do my program like this but I am not able to connect to the broker can anyone help me to find out what...
4 Aug 2021 by OriginalGriff
Um ... are you sure about that IP address? 127.0.0.1 is the loopback IP address also called "localhost". The address is used to establish an IP connection to the same machine or computer being used by the end-user. So it's unlikely to be the one...
19 Jun 2021 by Member 15245946
Hello, I am trying to make chat for two users(using select()), but i am stuck on this code: #include #include #include #include #include #include #include ...
19 Jun 2021 by Richard MacCutchan
As I told you yesterday you are referring to remoteportand localport, but you never initialise them to anything. Look at your main code: int main(int argc, char *argv[]){ int localport; int remoteport; int sock_fd; struct sockaddr_in...
18 Jun 2021 by Member 15245946
Hi, i have udp chat in C, but on terminal is written: Bind error : Permission denied, I tried a lot of different ports but nothing is working. What can be a problem? What I have tried: sock_fd = socket(AF_INET, SOCK_DGRAM, 0); ...
14 Jun 2021 by Member 15245946
Hi, I have client and server program. How can I make talker which combined server and client in one code, and how can client or server write more than one message(I think to use select()but I don't know how). Thanks What I have tried: I have...
14 Jun 2021 by Greg Utas
Combining a server and client probably isn't appropriate. They should run on different threads, which should also be separated from their work and GUI threads, respectively. All of them can be in the same .exe, though. Although it may be more...
2 Jun 2021 by Member 15228430
I can't connect to a MySQL server, so I stopped MySQL with: What I have tried: sudo /etc/init.d/mysql stop Quote: # Stopping mysql (via systemctl): mysql.service. sudo -s mysqld_safe --skip-grant-tables & Quote: # .... mysqld_safe...
24 May 2021 by José Silva 2021
hello, i'm making a messaging app using udp to handle clients and tcp to handle admin struct sockaddr_in si_minhaTCP,si_minhaUDP, si_outra; int nready, maxfdp1; int fdTcp; int fdUdp; fd_set rset; if (argc != 4) { printf("server {client...
24 May 2021 by KarstenK
My tip is that the receive is waiting to get the FULL buffer read - but it doenst get so much data. Read only 1 byte and use a loop. The typical issue in such code is that one side is in some bad state, so it doesnt work like socket closed,...
15 Apr 2021 by Member 14743579
Here is my updated code which is used to established a multiple connection and send data to device/client from server but my server does not receive a data from client, how to solve this issue please help me to solve this issue. What I have...
15 Apr 2021 by DeepsMann
Hye,1. I have to program a server which can listen multiple clients on a single port (say 8080).2. Once connection is established with a client, communication starts between client and server. Client sends - Server Receives, then Server sends - Client receives.3. If multiple Clients are...
14 Apr 2021 by Richard MacCutchan
You were given some suggestions over a week ago at How to connect multiple devices with server using TCP?[^].
1 Apr 2021 by Mohammad Tavoosi
I want to run this [C# remote desktop program] or every simple C# Server-Client socket app over the internet network but it does not work on the internet network although it works on the LAN network because of the NAT table. To solve this...
1 Apr 2021 by Richard MacCutchan
You should post your question in the forum at the end of the article. The author will be the best person to answer it.
17 Mar 2021 by Jeevan83
I am a beginner want to do a GUI based server client TCP based programming in visual studio. cannot find it on net. please give me any completed programs or sources from where I can perfectly learn.
16 Mar 2021 by Member 14743579
Actually i have created a server using tcplistner and i am using the below code to get the data and paste it on the textbox but my client device sent me a data in garbage value. i am using stream reader to read the data but i think it's not...
16 Mar 2021 by OriginalGriff
Quote: actually a client is a device,this device send me a binary data but my code shows me a garbage values like ??A@ and some other characters. how to read binary data from device and display the data in textbox. And then you do this: string...
16 Mar 2021 by Afzaal Ahmad Zeeshan
There can be several issues with the code, starting with the encoding of the content. It also depends on what you are sending. In your code, you do not show what the client is sending, only what you are reading on the server-side. It might be...
6 Mar 2021 by Member 14915174
Hello, I may have asked the same question but in c++ not too long ago, sorry if I'm a bit noisy. so I got two function to send and receive large data from tcpsockets in ruby but I need help debugging. the problem is I tested these methods on an...
1 Mar 2021 by Member 14915174
Hello, This is my first time trying to write an actual program in C++ my program communicates using sockets and I faced some problems, I tried to implement file transfer functionality. when I used to code similar programs in python I would first...
1 Mar 2021 by CPallini
Compile and run the following program #include #include using namespace std; int main() { string s = "foo bar 01234567890"; cout
25 Feb 2021 by Rick York
I don't have an exact solution for you because I have no idea what constraints you have to deal with. I can give you a tip though - use a little header structure to preface your data. It doesn't have to be very complex. I usually put the size...
25 Feb 2021 by Richard MacCutchan
There lots of examples online: C++ tcpip - Google Search[^]. However if you cannot understand any of them then you probably need to focus on studying C++ in greater detail.
25 Feb 2021 by CPallini
You could try ASIO[^]. It is somewhat difficult to grasp, at first. But there are many many working examples.
24 Feb 2021 by ibrahim shabbir
I created a program but it does not accepting multiple connection only get one connection and receive datafrom that device only What I have tried: public void StartListening(string IP, int port, Boolean test) { try ...
10 Feb 2021 by Umut Comlekcioglu
I developing a software and its will work in Android. Also, for my Android App, I'm developing Windows App too and they all need to connect MSSQL Server.I configure to SQL Server and I can connect SQL Server with Windows App and Android Emulator. But I can't connect my SQL Server with real...
10 Feb 2021 by Gabriel Lassonde
Hi! I am a professional programmer but I am very new to network programming. As an hobby, I am studying asio and socket programming. I have create rudimentary client/server programs (one connects the other accepts). Nothing fancy really. I run...
10 Feb 2021 by Rick York
If you are using TCP/IP for transferring data then it is not corrupting the data. The protocol has checksums and integrity checks built-in and packets are sent in order. If your data is corrupt then either you are sending it that way or it is...
10 Feb 2021 by RickZeeland
Could be a buffer problem as you exceed 65K, see: boost::asio::async_write, writing data larger than 65536 bytes - Stack Overflow[^] Also see CodeProject article: Socket Programming in C++ using boost.asio: TCP Server and Client[^] As suggested...
4 Feb 2021 by Mohammad Tavoosi
I have a very simple C# client/server chat application with TCP/IP Protocol that it works on local network but I want to use it on internet network but it seem is not easily in C# and I must to do port forwarding on server router or use SSH...
4 Feb 2021 by OriginalGriff
Have a look here: SignalR - Simple Chat Application in C#[^] - it's a lot simpler than trying to use TCP/IP directly.
26 Jan 2021 by Member 14530069
hi i work on a small project which includes socketcommunication. Specifically a TLS connection to a server. The Serverside works so far. But the client seems to block all parallelism tasks. Does anybody know where to get a sample with Sockets...
26 Jan 2021 by Richard MacCutchan
You need to set the blocking mode on the socket: Socket.Blocking Property (System.Net.Sockets) | Microsoft Docs[^]
2 Jan 2021 by Dev Parzival
SocketPro/src at main · Udesh-Ranjan/SocketPro · GitHub[^] Its a link to the source . There are two class files one is SockServer and the other one is SockClient. It runs ok in localhost I would like to run the server on my pc and the client in...
2 Jan 2021 by Afzaal Ahmad Zeeshan
Quote: It runs ok in localhost I would like to run the server on my pc and the client in my girlfriend's pc . If the code works fine, then the next step is to get a static IP for your PC and then connect to the SockServer instance using that IP...
31 Dec 2020 by Richard MacCutchan
See Java sockets - Google Search[^] for plenty of examples. And for general Java learning go to The Java™ Tutorials[^].
31 Dec 2020 by OriginalGriff
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us...
14 Dec 2020 by rmds
My struct: typedef enum { SEND_FILE = 0, FILE_SIZE = 10, }CommandList; typedef struct { CommandList command; char DataBuffer[PAYLOAD_SIZE]; } COMMAND_HEADER; struct Command_Data { char message; }; void some_unnamed_function() { ... COMMAND_HEADER...
14 Dec 2020 by Member 15021084
My solution is to use a union : typedef struct { double value1; long value2; } t_myStruct; typedef union { unsigned char asChar[sizeof(t_myStruct)]; t_myStruct data; } t_myData; t_myData mydata; then assign values to mydata.data.value1...
13 Dec 2020 by Mohammad Tavoosi
I want to create some networking apps with C# socket programming and use them over the Internet so I have to use Public IP to access Computers over the internet network. A way to do this is do port forwarding on server side router but my apps...
13 Dec 2020 by RickZeeland
Take a look at SignalR, here is an example on CodeProject: Beginner's Guide to Using SignalR via ASP.NET[^]
2 Dec 2020 by VidyasagarSTGM
I need to check the KeepAlive time and interval value for my Windows 2012 R2 Server. I tried checking "regedit" in this path\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parametersbut I am not able to find it. Is there any other way to check it or If I am wrong please...
2 Dec 2020 by devhi0000
Hello. By default there is not data in that key: https://www.guidetotcpip.com/wp-content/uploads/files/Appendices/tcpip5e_WindowsRegistrySettings.pdf[^] Things that you may want to know about TCP Keepalives | Microsoft Docs[^]
9 Oct 2020 by User 14926697
I want to connect two OS with each other and I'm using this code: #include #include #include #include #include #include #include #include #include...
9 Oct 2020 by OriginalGriff
Probably it's your compiler / linker command line. Have a look at this, and compare what you use with the solution there: c++ - MinGW linker error: winsock - Stack Overflow[^]
16 Sep 2020 by TheLostBoy201508
I have modified the QEMU v5.1 by adding the command pmemaccess of the version of the PANDA v1.0 of moyix, that command serves to expose the memory of a VM through a domain socket, and together with volatility, both are used to see live the guest...
13 Aug 2020 by Member 10199486
I have 100K of iot devices connecting on tcp server. I have to select specific services to be executed on each device based on the device id. Right now I am using a rest api, that I call upon when a device connects to the server,which in turn...
2 Aug 2020 by Zhivko Kabaivanov
I am using a MailSystem[^] library to check Gmail account every 10 minutes. In my application, I connect/log two different Gmail accounts at startup. Whenever I switch the checking emails methods, I receive the exception: Exception: Unable to...
23 Jul 2020 by honey the codewitch
Explore adapting Socket's async model to a task based one and adding some awaitable socket operations to your projects