sockets

Why strcmp function is not comparing the received command from the user with LIST ( without strcmp the function is working )

旧街凉风 提交于 2021-01-29 19:42:41
问题 I am new to socket programming, I am writing an FTP server without the client I have to access the server using netcat localhost port void do_job(int fd) { i,client; char command[DEFAULT_BUFLEN]; while((client =recv(fd, command, strlen(command), 0)) >0 ) { if (strcmp(command,"LIST") ==0) { } in the main function : if ((pid=fork()) == 0) { close(listenfd); do_job(fd); printf("Child finished their job!\n"); close(fd); exit(0); } 回答1: You need to add a null terminator to the string in order to

Socket connection not working with no-ip address

痴心易碎 提交于 2021-01-29 18:43:55
问题 I am having an issue with my socket connection. When I replace my no-ip address with "localhost" it works fine, but as soon as I put in my no-ip address, it cannot connect. I have forwarded the port from my router (port 12345 TCP and UDP forwarded to my local IP address 192.168.1.116). I don't understand why it would work with "localhost" but not with "myaddress.no-ip.org". It was of my understanding all you had to do was forward the port on your router to your local IP address. 回答1: You can

How to deal with multiple part network chuncks of data?

巧了我就是萌 提交于 2021-01-29 18:33:15
问题 I'm writing a network client for a given protocol using TCP and I'm having having some philosophical issues with the overall architecture of the thing. Sometimes it may happen that I don't have the whole request data and I may need to read a few more bytes than what's available at the moment, and I imagine sometimes I can get parts of another request after the one I want. What's the usual approach in this kind of situations? 回答1: TCP sockets are Stream-Oriented. That means that reading them

Binding a port for client tcp socket

蹲街弑〆低调 提交于 2021-01-29 15:44:56
问题 I have a problem about 'binging a local port for a client tcp socket'. The code is as below: void tcpv4_cli_connect(const char *srvhost, in_port_t srvport, const char *clihost, in_port_t cliport) { struct sockaddr_in srvaddr, cliaddr; struct in_addr inaddr; int sockfd; bzero(&srvaddr, sizeof(srvaddr)); inet_aton(srvhost, &inaddr); srvaddr.sin_family = AF_INET; srvaddr.sin_addr = inaddr; srvaddr.sin_port = htons(srvport); bzero(&cliaddr, sizeof(cliaddr)); inet_aton(clihost, &inaddr); cliaddr

C# socket read error

佐手、 提交于 2021-01-29 14:27:34
问题 In my program i'm creating socket and whes client connects i'm creating new thread and trying to read and write from/to connected to this socket, but alway get an Read Error because host-computer closed connection for the second command, first command from client worfs fine, and third works fine. i try to check if clientSocket is connected and if networkStream is readable and they alway returns true. how can i solve this? and how can it be - networkStream.CanRead returns true but

ssl connection with tls server and letsencrypt

一曲冷凌霜 提交于 2021-01-29 14:01:29
问题 I try to do ssl connection for my server in c. i have take this code : https://wiki.openssl.org/index.php/Simple_TLS_Server and I have generated certificate with certbot: sudo certbot certonly --standalone I have copy cert.pem and privkey.pem present in /etc/letsencrypt/live/MY_DOMAIN/ on my program directory. but when I try to connect with curl, I get this error: curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: https://curl.haxx.se/docs/sslcerts

Python TCP networking inconsistencies

大城市里の小女人 提交于 2021-01-29 13:46:26
问题 I'm new to networking and I'm trying to write a simple TCP client. The first thing I have to do is to send my message length and wait for further instructions. Here's my code: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) s.send(bytearray(message_serialised_length)) data = s.recv(BUFFER_SIZE) s.close() print("response: {}".format(struct.unpack('>I', data))) Sometimes, i'm able to get a response and the program continues but other times I run into this

Can't remotely connect to Python Socket

核能气质少年 提交于 2021-01-29 13:33:18
问题 I have created a chat application using python sockets and Tkinter and it all works perfectly locally however the Client is unable to connect to the server remotely (when I enter my public IP address as the host) I have already fully port-forwarded my network and I know how to port forward very well and when I run an online Port Open scanner that checks if a port is open it states that the port is open!? I have port-forwarded my router on a number of ports and updating the client and server

Why am I receiving data when my Socket has disconnected? [duplicate]

左心房为你撑大大i 提交于 2021-01-29 11:58:27
问题 This question already has an answer here : TCP Socket is not stopping receiving data in C# program (1 answer) Closed 21 days ago . I'm having an issue with my Sockets. Basically I have a few listeners that listen on all the available ports on my pc. When a socket connects to one of the listeners, I open a new Socket-connection to handle that connection and my listener goes back to listening. However when a client disconnects I keep on receiving empty data. As you can see in the code below, I

Communicating between a php web server and a C# desktop application

点点圈 提交于 2021-01-29 10:47:48
问题 I have a web service with php which is listening to some other services and receive some messages. After getting the message I want to deliver it to my desktop application. I don't want that my desktop app call my web service to see the message, instead I want to push my message to desktop app. In C# we can listen to pipe when it changes. But don't have any idea how to deal with it in php. Or maybe I use socket between desktop app and web service. Any idea would highly appreciated. 来源: https: