How can I establish my socket connection using the Windows command line?
For example, my socket IP and port num is 192.168.1.180:9760
I just want to send commands to that IP from the command line.
Bind socket to a port It needs a sockaddr_in structure similar to connect function. int socket_desc; struct sockaddr_in server; //Create socket socket_desc = socket(AF_INET , SOCK_STREAM , 0); if (socket_desc == -1) { printf("Could not create socket"); } //Prepare the sockaddr_in structure server.
The socket command may be used to open either the client or server side of a connection, depending on whether the -server switch is specified. Note that the default encoding for all sockets is the system encoding, as returned by encoding system.
The client application uses a connect() API on a stream socket to establish a connection to the server. The server application uses the accept() API to accept a client connection request. The server must issue the bind() and listen() APIs successfully before it can issue an accept() API.
The following code opens a connection to a server: Socket socket = new Socket( server, port ); Once our socket instance is connected to the server we can start obtaining input and output streams to the sever. Input streams are used to read data from the server while output streams are used to write data to the server.
You can use "netcat", or "nc" as it is sometimes called.
So if the server is using UDP on port 9760, you can use:
nc -u 192.168.1.180 9760
You can use telnet as in
telnet 192.168.1.180 9760
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With