Sockets on Same MAChine for Windows and Linux

Sockets On Same Machine For Windows and Linux

As for TCP performance, I have done this sort of test recently on an HP-UX server (8 Intel Itanium 2 processors 1.5 GHz 6 MB, 400 MT/s bus) and on Red Hat Linux (2 IA-64 1,6 Ghz). I used iperf in order to test TCP performance. I found that speed of TCP exchange is more than ten times faster when I run iperf on the same machine comparing to running iperf on two different machines.

You can also give it a try as there are options that might be of interest to you - length of buffer to read or write, set TCP no delay and so on. Also you can compare speed of TCP exchange on Windows machines as there is a version of iperf for Winddws.

This is a more detailed comparison:

1) Speed of TCP exchange between two iperf applicatons running on different HP-UX server, default TCP window 32K: 387 Mbits/sec

2) Speed of TCP exchange between two iperf applicatons running on different HP-UX server, TCP window 512K: 640 Mbits/sec

3) Speed of TCP exchange between two iperf applicatons running on the same HP-UX server, default TCP window 32K: 5.60 Gbits/sec

4) Speed of TCP exchange between two iperf applicatons running on the same HP-UX server, default TCP window 512K: 5.70 Gbits/sec.

5) Speed of TCP exchange between two iperf applicatons running on the same Linux server, TCP window 512K: 7.06 Gbits/sec

6) Speed of TCP exchange between two iperf applicatons running on HP-UX and Linux, TCP window 512K: 699 Mbits/sec

Python socket connection between Windows and Linux

there how you setup tcp :

the server :

#!/usr/bin/env python

import socket


TCP_IP = '127.0.0.1'
TCP_PORT = 5005
BUFFER_SIZE = 20 # Normally 1024, but we want fast response

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)

conn, addr = s.accept()
print 'Connection address:', addr
while 1:
data = conn.recv(BUFFER_SIZE)
if not data: break
print "received data:", data
conn.send(data) # echo
conn.close()

the client :

#!/usr/bin/env python

import socket


TCP_IP = '127.0.0.1'
TCP_PORT = 5005
BUFFER_SIZE = 1024
MESSAGE = "Hello, World!"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()

print "received data:", data

Sockets in windows vs linux

Presumably their implementations are very different (Though it's hard to tell, as the windows source code isn't available.).

Both provides a rather similar API for programmers to use, based on the BSD socket api , and the socket API for various programming languages are a wrapper around that native C API.

socket programming with linux and windows in c language

Yes, you can use sockets to talk between different OSes. The APIs may or may not be identical, but everything should work.

The main thing you have to take care of is the byte order when sending data on the wire. This link explains byteorder and how to do it right.

Socket programming between linux client and linux/windows server and android

You can set up communication between same platform or cross platform clients/server. If you're sticking to *nix platform, you can try out with unix sockets. Since cross platform being a better option, you can implement the same thing using node.js and sockets. For better insight upon socket.io,please go through http://socket.io/

C Server/Client with Sockets

It won't work because you never call connect(). You should check return value from calls like connect() , send () etc.

The solution : You should call connect after you created the socket.

connect(mySocket, (SOCKADDR *)&serverAddress, sizeof(sockaddr_in));  

To use send or sendTo with TCP, the socket has be connected or you will get an error.

send(mySocket, question, strlen(question), 0);


Related Topics



Leave a reply



Submit