Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to establish socket connection using the command line

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.

like image 779
Shiva Avatar asked Dec 03 '13 08:12

Shiva


People also ask

How do I run a socket program in terminal?

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.

What is socket command?

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.

How a connection between client and server is established in socket programming?

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.

What is the proper code to initialize connection of socket to server?

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.


2 Answers

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
like image 153
Mark Setchell Avatar answered Oct 27 '22 01:10

Mark Setchell


You can use telnet as in

telnet 192.168.1.180 9760
like image 39
Scary Wombat Avatar answered Oct 26 '22 23:10

Scary Wombat